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
0
votes
1 answer

Zendframework 3 - Overwrite CSRF Validator

I try to migrate from ZF2 to ZF3 but many viewHelpers and validators do not work. But only the ones who overwrite ZendFrameworks viewhelpers / validators do not work... I want f.e. to overwrite the CSRF validator to allow a higher timeout by…
0
votes
2 answers

Zend Form Validating of required elements

I have the required element in my Zend Form: $name = new Zend_Form_Element_Text('name'); $name->setLabel('Name') ->setValue(isset($plan)?$plan['name']:'') ->setRequired() ->setAttribs(array('class' => 'required', 'maxlength' => 50)) …
Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
0
votes
1 answer

ZF2 + Doctrine 2 - Entity created when requirements not met and values empty

Extending on 2 previous questions about form structure and validating collections I've run into the next issue. My form validates properly. Including included collections by way of Fieldsets. But the innermost Fieldset should not result in an…
rkeet
  • 3,406
  • 2
  • 23
  • 49
0
votes
2 answers

zend validator Zend_Validate_EmailAddress does nothing: site config looks OK, but probably isn't

Baffled again. (Zend Framework 1.11.1) I've just added a validator to a VERY simple form, and nothing happens when invalid data is entered. The code: $form = new Zend_Form; $form->setAction('/MyController/reponsepage') …
confused
  • 31
  • 1
  • 4
0
votes
3 answers

having problems with zend validator regex for a number - integer or optional float

I'd really appreciate some help with this its been driving me nuts. I'm trying to validate numbers submitted by a zend form either in the form of integers or decimals (2 decimal places) allowing for 0 or 0.00 but not empty inputs.…
annette
  • 181
  • 1
  • 1
  • 6
0
votes
1 answer

Checking a password is identical to another input one

I need to check that a typed in password is what the user thinks is typed in. For this I ask for the password to be typed in twice. I have some existing validation in place but nothing for multiple fields yet. I wondered how to have the validator…
Stephane
  • 11,836
  • 25
  • 112
  • 175
0
votes
1 answer

How to check for duplicate email entries while registering new users in zend framework 3

I want to duplicate email validation to registration page.For now the following validation is implemented on email. $inputFilter->add(array( 'name' => 'email', 'required' => true, 'filters' => array( …
Chaitanya Sairam
  • 121
  • 1
  • 2
  • 16
0
votes
1 answer

How to customise the Regex validation messages in a Zend\Form keeping them reusable?

The default validation error message for Regex is "The input does not match against pattern '%pattern%'" I can replace it by a custom one like "Please make an input according to the pattern '%pattern%'" But then I still have a not really…
automatix
  • 14,018
  • 26
  • 105
  • 230
0
votes
2 answers

How to set a custom error message for a required form field in Zend Framewor 2?

In my Form I have a Fieldset, that contains two elements foo and bar. The business rule for them is, that one has to be set. So, the fieldset is valid, when foo OR bar is set, and invalid, when no-one is set. I solved this as follows: public…
automatix
  • 14,018
  • 26
  • 105
  • 230
0
votes
0 answers

How to make a field validation dependent on a field of another Fieldset in ZF2?

In my form I have some fields, that should be validated depending on some field(-s) in another sub-fieldset of the Form: MyForm - [fieldset] main instanceof WhatEverFieldset -- [fieldset] foo instanceof FooFieldset --- [field] field_a --- [field]…
0
votes
1 answer

Zend Framework: is there a way to access the element name from within a custom validator?

I'm writing a custom validator that will validate against multiple other form element values. In my form, I call my custom validator like this: $textFieldOne = new Zend_Form_Element_Text('textFieldOne'); $textFieldOne->setAllowEmpty(false) …
Andrew
  • 227,796
  • 193
  • 515
  • 708
0
votes
1 answer

Unable to use custom validators in ZF2 when creating form using factory

Was wondering if anyone has come across this problem previously. I am using the preconfigured form spec to create form using the Zend\Form\Factory, I am also injecting the FormElementManager into the factory so it can find my custom elements…
0
votes
1 answer

Can implement dynamic validation on element level?

Can implement dynamic validation on element level? I used this example to implement validation of one element dependent on the value of the other element. But for this purpose I'll need to implement this for every single form where I use this…
vlr
  • 780
  • 4
  • 16
  • 33
0
votes
1 answer

How to integrate the element label into the validation error message in ZF2?

I have a form, where the error messages have to be displayed bundled at one place. The default messages are general, so the user sometimes doesn't know, which message is for which form field: A record matching the input was found Value is required…
0
votes
1 answer

zf2 inputfilter - how to return a failed custom validation

I am using an input filter with standard ZF2 validators/filters. However i am also extending the \My\InputFilter::isValid method to include domain-specific validation, such as comparing specific parts of dates. Within this method, how do i signal…
John Crest
  • 201
  • 1
  • 4
  • 24