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
1
vote
1 answer

How to include EntityManager in ZendFramework 2 AbstractValidator

I have a custom validator, extending Zend AbstractValidator. The thing is, i want to include Doctrine EntityManager, but i keep failing! I tried to make a Factory for my Validator, but it doesn't seem to work. Help!! What am I doing…
user7867306
1
vote
2 answers

ZF2/Doctrine2 - Fieldsets not validated, data is always valid

I've set up a structure using Abstract classes for Forms, Fieldsets and InputFilters. Forms and Fieldsets have Factories while InputFilters are created and set on the Fieldsets by the FieldsetFactory (uses the MutableCreationOptionsInterface to pass…
1
vote
2 answers

How can validate multidates in element with regexp PHP Zend Framework

I have field input with multidatepicker select, multidatepicker enter dates in field like: 2016-10-02, 2016-10-13, 2016-10-25. How can validate all dates or one, maybe I can with array regexp validator if exist? $element_edit->addValidator…
1
vote
2 answers

Problem with zend validate on zend form element

I used to have this form element to validate an email and display an error message if the format was invalid: $email_users = new Zend_Form_Element_Text('email_users'); $email_users->setLabel('Email:') ->setRequired(false) …
1
vote
1 answer

How to get additional Form error messages translated in ZF2?

I have a Form where I have to perform a validation after the basic form validation (extending/overriding the Form#isValid(...)). If this "post-validation validation" fails, I add an error message to the Form like this: MyForm extends Form { …
automatix
  • 14,018
  • 26
  • 105
  • 230
1
vote
1 answer

Zend changing validation error behavior: wrapping element in another tag

I've set a validator for the email so it can't be empty. This is the markup of the usual form that zend_form generates:
jblue
  • 4,390
  • 4
  • 46
  • 79
1
vote
1 answer

How to debug a Zend\Form?

In a project I have a huge form -- with many fields, nested fieldsets, collections etc. The form validation is failing and I don't know, why. How should such a problem be handled? What is a good, efficient approach to find out, why a form validation…
automatix
  • 14,018
  • 26
  • 105
  • 230
1
vote
1 answer

zf2: how to inject service into custom form validator from listener

I am trying to apply custom validator when a new user (ZfcUser) registers to the system. The validator supposed to use a service. I am trying to inject service through the factory, but it looks like code in the factory never get a chance to run and…
vlr
  • 780
  • 4
  • 16
  • 33
1
vote
2 answers

Trouble with date and time formats saving in my database

I have trouble saving my date and time values. I tried different formats, here the actual try. validator in my form: $datum=$this->CreateElement('text','datum') ->setAttrib('size', '10') ->addValidator(New…
pia-sophie
  • 505
  • 4
  • 21
1
vote
1 answer

Recommended place for pre-translated Zend Framework resources

Since zf 1.10 Zend Framework ships with pre-translated validation messages. They are outside the library path. The manual illustrates how to load these in your bootstrap. $translator = new Zend_Translate( 'array', '/resources/languages', …
Exception e
  • 1,864
  • 3
  • 19
  • 33
1
vote
1 answer

Zend_Validate_Abstract custom validator not displaying correct error messages

I have two text fields in a form that I need to make sure neither have empty values nor contain the same string. The custom validator that I wrote extends Zend_Validate_Abstract and works correctly in that it passes back the correct error messages.…
1
vote
1 answer

Zend Form Validation set error messages

I have setup a form along with filters and validators which seem to work correctly. However, I can not seem to get custom error messages to work. So far I have tried. $inputFilter->add(array( 'name' => 'message', …
Garry
  • 1,455
  • 1
  • 15
  • 34
1
vote
2 answers

setMessage for Zend_Validate_EmailAddress doesn't work

I have a form and I want to set my custom errors in it. I am using Zend, and I have the following code... //Create validators $formMustBeEmail = new…
iSenne
  • 2,656
  • 5
  • 26
  • 26
1
vote
1 answer

How do I write a custom validator for a zend form element with customized error messages?

I have a question field with a list of allowed characters : A-Z,0-9,colon (:), question mark (?), comma(,), hyphen(-), apostrophe ('). I have the regex which works fine, in the fashion : $question->addValidator('regex', true, array(
1
vote
1 answer

Difference between InputFilterAwareInterface and InputFilterProviderInterface in ZF2

Can someone explain me the difference between both interfaces InputFilterAwareInterface and InputFilterProviderInterface? Both seem to serve to the same purpose, to get an InputFilter, but I know they cannot be the same... And when do they get…
vicaba
  • 2,836
  • 1
  • 27
  • 45