Questions tagged [zend-validate]

Zend Framework provide the validate class to validate the forms elements. Zend have this class in library. This tag is for validation in zend framework.

The Zend_Validate component provides a set of commonly needed validators. It also provides a simple validator chaining mechanism by which multiple validators may be applied to a single datum in a user-defined order.

Zend_Validate supplies a set of commonly needed validators, but inevitably, developers will wish to write custom validators for their particular needs. The task of writing a custom validator is described in this section.

Zend_Validate_Interface defines two methods, isValid() and getMessages(), that may be implemented by user classes in order to create custom validation objects. An object that implements Zend_Validate_Interface interface may be added to a validator chain with Zend_Validate::addValidator(). Such objects may also be used with Zend_Filter_Input.

As you may already have inferred from the above description of Zend_Validate_Interface, validation classes provided with Zend Framework return a boolean value for whether or not a value validates successfully. They also provide information about why a value failed validation. The availability of the reasons for validation failures may be valuable to an application for various purposes, such as providing statistics for usability analysis.

Basic validation failure message functionality is implemented in Zend_Validate_Abstract. To include this functionality when creating a validation class, simply extend Zend_Validate_Abstract. In the extending class you would implement the isValid() method logic and define the message variables and message templates that correspond to the types of validation failures that can occur. If a value fails your validation tests, then isValid() should return FALSE. If the value passes your validation tests, then isValid() should return TRUE.

223 questions
2
votes
2 answers

Zend Form can't validate float number

I have this form element: $this->addElement('text', 'prezzo', array( 'label' => 'Prezzo (*)', 'filter' => '', 'description' => 'Il prezzo non è comprensivo di sconto, ma se previsto verrà calcolato', 'required' =>…
2
votes
1 answer

ZF2 inputfilter doctrine NoObjectExists editing object does not validate

So i got a ZF2 application, got a Form and a InputFilter in the InputFilter i have: $this->add( array( 'name' => 'email', 'required' => true, 'validators' => array( array( …
2
votes
2 answers

Zend\Form\Form not displayin error message from custom validator

I'v creatated a custom validator: class MyValidator extends AbstractValidator { const ERROR_CONST = 'error'; protected $dbAdapter; protected $messageTemplates = array( self::ERROR_CONST => "Error msg for '%value%'." ); …
Borje
  • 255
  • 5
  • 19
2
votes
1 answer

How to tell the Zend validator to use the only one validation message in any way

I've added the EmailAddress validator to my form element and when I'm trying to submit something like test, it shows me 2 errors: * The input does not match against pattern '/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/' …
2
votes
2 answers

zend framework 2 - compare 2 inputs using validator?

I'm new to zend framework 2 and I have a question on comparing two inputs in the factory-backed form. My scenario is like following: I want to compare two inputs, for example, $startDate and $endDate. I want to validate that $startDate is always…
2
votes
4 answers

Zend_Validate_Db_RecordExists exclude logic issue

I've got a form for a job application, where administrator needs to pick from the list of certain user ids. The list contains only user ids of type "employer", however I want to validate the administrator input, so if he manually inserts an id that…
eithed
  • 3,933
  • 6
  • 40
  • 60
2
votes
2 answers

Validating YYYY-MM-DD formatted strings with Zend_Validate_Date in en_US locale

I'm validating a user-entered date string in YYYY-MM-DD format using Zend_Validate::is($value,'Date'). This call creates this…
farzad
  • 8,775
  • 6
  • 32
  • 41
2
votes
1 answer

Zend_Filter_Input with Zend_Validate_InArray-Validator which has an array as its needle

I'm using Zend_Filter_Input to filter and validate my data. For a field (gender), I am using the Zend_Validate_InArray to validate, if the value is in array('m', 'w'); So far so good. While running my UnitTests, I noticed, that an empty array is a…
Tom
  • 63
  • 1
  • 6
2
votes
1 answer

Zend_Validate::is() Static Check, get validation message work around

Does anyone know of a way to get validation messages from using Zend_Validate in static scope? Zend_Validate::is($value, $validator[0], $validator[2]) The docs say explicitly that getting the messages isn't an option:…
four43
  • 1,675
  • 2
  • 20
  • 33
2
votes
1 answer

How to filter / validate for a boolean value?

i was just reading a great presentation about Quality Assurance for PHP Projects by Michelangelo van Dam aka DragonBe. In his presentation he uses Zend-Framework as an example, which i am familiar with on a basic level. Since i want to improve…
Sam
  • 16,435
  • 6
  • 55
  • 89
2
votes
1 answer

zend_validate_regex not happy with accented characters

so I'm using Zend_Framework and I need to validate a text and accept not only digits and normal letters, but also some guys like 'ã', 'ç' and so on... I was confident that a simple regex validation would do the job: public function…
1
vote
2 answers

Zend Validate: How to validate each separate value in comma separated values in textarea for zend_validate_DbRecordExist?

I have text box in which your adds values in comma separated values. Once the form is post I want to check each of CSV value against database table that if each one of them exist already. If so then I want to throw error message otherwise that is…
Rajan Rawal
  • 6,171
  • 6
  • 40
  • 62
1
vote
2 answers

How to modify zend Db_RecordExists validator where clause?

I want to add check for more than one values in where clause. Db_RecordExists just check for one filed. I have read that you can extend zend validate abstract class and you can have your own validator. can I have one little example about this…
Rajan Rawal
  • 6,171
  • 6
  • 40
  • 62
1
vote
1 answer

Phone number validation using zend framwork

I am using below code to validate by phone number in my project, $phone = new Zend_Form_Element_Text('phone', array( 'label' => $view->_('phone'), 'value' => '', 'class' => 'text-size text hastip', 'title' =>…
mymotherland
  • 7,968
  • 14
  • 65
  • 122
1
vote
1 answer

Strange issue with Zend_Validate_Identical?

I had write the following code in my Zend Form: $newpassword = new Zend_Form_Element_Password('newpassword'); $newpassword->setLabel("Enter your New Password :") ->setRequired(true) ->addFilter('StripTags') …
Pushpendra
  • 4,344
  • 5
  • 36
  • 64