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

zf2 validator - valid only if date is a weekday

Using ZF2 \Zend\Validate, is it possible to validate a date only if it is a weekday? So weekends, regardless of month or year, will fail the validation? The input is a normal text field.
John Crest
  • 201
  • 1
  • 4
  • 24
0
votes
0 answers

zend form validation is not working using callback validator using zend framework2

I have a problem in validating the array of value of an element. I search a lot find a callback function to validate that data. Below is the validation code which i am using but it is not working
Azhar Ahmad
  • 183
  • 12
0
votes
3 answers

Set NotEmpty validator error message

I am trying to set a custom error message with ZF2 form and the NotEmpty validaor. In my form I have the following radio element. $this->add(array( 'name' => 'paymentMethod', 'type' => 'Radio', 'options' => array( 'label' =>…
Garry
  • 1,455
  • 1
  • 15
  • 34
0
votes
1 answer

zend_validate_postcode via country?

i have a registration form which contains a postalcode and a country drop down given those two values i want to validate the postcode via zend_validate_postcode this validator wants a zend_locale in the constructor now i dont know how to create a…
John Doe
  • 2,746
  • 2
  • 35
  • 50
0
votes
1 answer

zf2 csrf not working

We can easily break CSRF of ZF2. If we remove the string after the hyphen(-) the CsrfValidator does not give any error and the token is successfully submitted. For example CSRF token = 245454547kck-kjhjh2454dh after editing the token token =…
Hiren Shah
  • 225
  • 1
  • 10
0
votes
1 answer

zend\form\element\select with multiple attribute: how to override default notEmpty validation error?

My Zend\Form includes a Zend\Form\Element\Select with the attribute 'multiple' => 'multiple' and a NotEmpty validator with a custom isEmpty error message. With the multiple attribute set, when I submit the form without selecting any options, I get…
David
  • 815
  • 8
  • 18
0
votes
1 answer

Validating objects with Zend\Validator

I'm trying to use Zend\Validator to validate objects but I find it hard for a couple of reasons and am now wondering if I'm doing something fundamentally wrong or if the component is just not a good choice to do so… Ideally I'd like to…
pitty.platsch
  • 77
  • 1
  • 13
0
votes
1 answer

Zend Framework: How to filter input, turning zero to null, then validate null?

So I've determined that my validator does not get called when I filter the input value and turn zero into null. $this->addElement('select', 'State_ID', array('label' => 'State', 'multiOptions' => $this->getStates(), 'validators' =>…
Andrew
  • 227,796
  • 193
  • 515
  • 708
0
votes
1 answer

How to send field name for required true validation in zend

Here is what my form field, $this->addElement( 'text', 'title', array( 'placeholder' => 'Title', 'class' => 'form-control', 'required' => true, 'filters' => array( 'StringTrim' ), …
Rohit
  • 657
  • 6
  • 25
0
votes
1 answer

ZF2 form validation against bounded entity

i have an entity with an end date property. If the user edits the entity and changes the date, it shouldn't be allowed that the new date is before the date it was before. Is it possible to get the bounded entity in my validator to check the dates or…
Dominik Barann
  • 675
  • 2
  • 10
  • 25
0
votes
1 answer

validate input data with symfony, doctrine or zend_validate?

im using symfony with doctrine and zend. i wonder if i wanna validate the user input data, should i use validation from symfony, zend or even doctrine? i think i should go with symfony, but are there times the validation from zend or doctrine would…
never_had_a_name
  • 90,630
  • 105
  • 267
  • 383
0
votes
0 answers

How do I add callback validator with addElement in zend form?

I'm trying to create a simple Zend form using pm_Form_Simple class. I need a callback validator with its addElement method. Here's what I did. $form = new pm_Form_Simple(); $form->addElement('text','my_number', array('label'=>'Your…
Vipin Kumar KM
  • 356
  • 5
  • 17
0
votes
1 answer

Suspend file validation on Zend Framework

Currently on my application I have a form where I ask the user to upload an image file to be used as a logo. I want to allow the user to reset that to nothing by supplying no file (by just pressing the upload button from the browser). In this…
Dimitrios Mistriotis
  • 2,626
  • 3
  • 28
  • 45
0
votes
1 answer

Zf2 Callback Validator not passing all form values

Currently setting up a form using ZF2. I'd like to be able to setup validation for the form based on comparing the values of 2 different elements on the form. Where in the past I've used the Callback validator to pass in all of the forms values, it…
0
votes
1 answer

ZF2 Annotation Validators NotEmpty and Int not working?

I'm building a form in ZF2 from an entity and everything seems to work fine, except 2 of my validators are ignored for some reason. The Entity looks like this: /** * @var string $name * * @ORM\Column(name="name", type="string",…