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
4
votes
2 answers

Validating number of options in Zend Form Multiselect

I have an Multiselect Zend Form element with many options. I have to validate the number of selected options (at least N options and at most M options are selected). I want the error message to be printed in the form just like regular Zend Validate…
Matěj Zábský
  • 16,909
  • 15
  • 69
  • 114
4
votes
8 answers

Should validation be done in Form objects, or the model?

This question is mainly geared towards Zend in PHP, although it certainly applies to other languages and frameworks, so I welcome everyone's opinion. I've only recently been using the Zend framework, and while it's not perfect, I have had a pretty…
David Smith
  • 38,044
  • 11
  • 44
  • 61
4
votes
3 answers

Zend Model validation

I'm working on Zend application, but have no much experience with Zend, so just relying on my RubyOnRails experience. From couple articles I've found that most of validation is implemented on Forms level - with Zend_Form. But it looks a bit weird…
4
votes
3 answers

Date validator that validates if the date is greater than or equal to today with Zend Framework

$form = new Zend_Form(); $mockDate = new Zend_Form_Element_Text('mock'); $mockDate->addValidator(???????); $form->addElements(array($mockDate)); $result = $form->isValid(); if ($result) echo "YES!!!"; else echo "NO!!!"; Assumption that the…
Brant Messenger
  • 1,441
  • 11
  • 21
4
votes
2 answers

How to remove a validator from a Form Element / Form Element ValidatorChain in Zend Framework 2?

I read this question on SO: "how to disable inArray validator forms in zend framework2" and was trying to find it out, but couldn't find any way to detach/remove the InArray Validator. But InArray is just a validator. So how can remove a validator…
automatix
  • 14,018
  • 26
  • 105
  • 230
4
votes
2 answers

Zend Framework and string covertation using iconv

One site was moved to another server where is installed Solaris and other iconv settings. Now, when I validate anything with "StringLength" function from Zend Framework my scripts fail with this error: Notice: iconv_strlen() [function.iconv-strlen]:…
kubum
  • 469
  • 2
  • 13
4
votes
1 answer

Zend Form Validation and Filtering without Zend Forms

Is there a way to validate and filter pure HTML forms with Zend Validation and Zend Filter classes ? Please give some example if you have, I couldn't find out any.
Shaolin
  • 2,541
  • 4
  • 30
  • 41
4
votes
1 answer

How do I return a custom 'isEmpty' error message from Zend\Validator\Identical in Zend Framework 2?

Possible Duplicate: zendframework 2 inputfilter customize default error message I'm trying to use Zend\InputFilter\InputFilter to validate the input from a registration form. I have the code below that: Validates the email address in the 'email'…
Neil
  • 105
  • 1
  • 3
  • 8
4
votes
2 answers

regex one dot or one underline validator

this is my regex ^(([a-z0-9]+)\.([a-z0-9]+)){4,20}$|^(([a-z0-9]+)\_([a-z0-9]+)){4,20}$ it's gonna be a word with a single dot OR a single underline OR no uderline and dot. i also want this expression between 4 and 20 chars (it's gonna be a…
shampoo
  • 1,173
  • 12
  • 22
4
votes
2 answers

Validating multiple optional form fields with Zend Framework

I am trying to validate Zend_Form which has several optional fields and I want at least one of them to be filled in. In my case I have mobile, home and office phone numbers and I want at least one of them to be provided. I am trying to achieve this…
gogh
  • 73
  • 1
  • 8
3
votes
1 answer

Using "." for decimals in zend validator float

I have a form with a element called "price". I validate this element with the "float" validator. The thing is when I insert, for example: 12,50 => it is valid but when I try to save it on the DB (mysql) it is saved as "12.00" So I wanna to change…
José Carlos
  • 1,005
  • 16
  • 29
3
votes
1 answer

Zend Validators and multidimensional array

How do i validate multidimensional array in Zend Framework (Zend_Filter_Input)? Example: Input must be array Input must have 'roles' and 'name' 'roles' must be array All element in 'roles' must be array All element in 'roles' must have 'name' and…
Morfi
  • 101
  • 1
  • 3
3
votes
2 answers

Zend MultiCheckbox: set maximum selection

Here I am again with an easy question. Is there an existing zend validator to set a maximum to the boxes an user can select. I want them to select no more than 3 boxes. I've searched the web and the only thing I've found was to set an error in the…
Tim
  • 662
  • 1
  • 7
  • 16
3
votes
1 answer

How to validate a field of Zend_Form based on the value of another field?

I'm trying to add a custom validator to a field. It should take into account the value of another field. E.g. field A should be at most B+50%. I've made a class implementing Zend_Validate_Interface, but apparently Zend Form only sends in the value…
Fluffy
  • 27,504
  • 41
  • 151
  • 234
3
votes
2 answers

Label of element as variable in error message for validation

Is it possible to use a variable inside the error message referring to the label of the form element? It's possible to map custom variables like %hostname% (in email validator) and the %value% is also available, but I'd like to have the form label…
Jurian Sluiman
  • 13,498
  • 3
  • 67
  • 99
1
2
3
14 15