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

Zend Framework - Where should we place our custom Validators?

We can read here how to write: http://framework.zend.com/manual/en/zend.validate.writing_validators.html class MyValid_Float extends Zend_Validate_Abstract { 1) Where should we place this? application/default/validators…
MEM
  • 30,529
  • 42
  • 121
  • 191
3
votes
2 answers

Why does Zend Framework Validate fail for MimeType, when calling isValid()

This has stumped me for the last few hours. // Using just straight up FINFO detects the mime type $oFileInfo = new finfo( FILEINFO_MIME_TYPE ); $sMimeType = $oFileInfo -> file($_FILES['myfile']['tmp_name'] ); …
Shane Stillwell
  • 3,198
  • 5
  • 31
  • 53
3
votes
3 answers

Clearing Validation Error Messages from a Zend Form Element

I have a form element for capturing email addresses. I am using Zend_Validate_EmailAddress on the element, and it generates error messages that aren't very user-friendly. My first step was to specify new messages that were more user-friendly, but…
Sonny
  • 8,204
  • 7
  • 63
  • 134
3
votes
3 answers

How to translate messages of a custom validator in Zend Framework?

I created a custom validator by extending Zend_Validate_Abstract to validate a CAPTCHA input regarding Zend_Captcha: class My_Validate_Captcha extends Zend_Validate_Abstract { const CAPTCHA = 'captcha'; protected $_messageTemplates = array( …
3
votes
1 answer

Zend Form Validation:: Does exist oposite validator to Identical?[how to check that input not identical to 'str']

Zend Form Validation: Is there a validator that is the opposite of Identical (i.e., notIdentical)? How would I check that an input is not identical to 'str'?
Ben
  • 25,389
  • 34
  • 109
  • 165
3
votes
1 answer

Zend Framework: How do I set a custom validator on a form element?

I'm writing a custom validator that checks that at least one field has a value. I want to validate that either 'namefield' or 'idfield' has a value. One of them can be empty, or both can have a value, but at least one of them must have a…
Andrew
  • 227,796
  • 193
  • 515
  • 708
3
votes
3 answers

Zend Framework: Conditional validation

I need to set up some validation for a form field based on a value of another field. For instance if profession is Doctor, then require specialty not to be blank ('') or none ('none'). $professionOptions = array( '' => 'Choose…
3
votes
3 answers

How to create a datetime validator in a Zend Framework form?

By default a Zend Framework date validator uses the date format yyyy-MM-dd: $dateValidator = new Zend_Validate_Date(); But I want to add hour and minute validation. In other words, I want to require the user to enter the hour and minute. But the…
Andrew
  • 227,796
  • 193
  • 515
  • 708
3
votes
1 answer

Zend Db_NoRecordExists - checking against multiple columns

Zend Db_NoRecordExists docs seem to be limited to checking only one column. Is there a way to check multiple keys when validating an entry? For example, I am allowing the same email address for different cities. here's my current…
user225195
  • 101
  • 1
  • 2
  • 6
3
votes
2 answers

Zend framework 2 how use validator chains in fieldsets

I need to use validator chains in the getInputFilterSpecification method of the fieldset to use the breakChainOnFailure parameter and get only one error message. I know make validator chains using InputFilter classes how explain the zend…
josepmra
  • 617
  • 9
  • 25
3
votes
1 answer

To add validation GreaterThan - Zend Form

setMethod('post'); $this->setLegend('Audience Details'); $this->addElement('text', 'audience_total', array( 'label' …
Ish
  • 28,486
  • 11
  • 60
  • 77
3
votes
2 answers

How to use identical field validation for add and edit operation in zend form?

I am a newbie to zend framework. I am developing a simple user registration application in zend. I have both add and edit functionalities in my application. I can add a new user perfectly using my application. But when I try to edit user …
minhaz
  • 503
  • 1
  • 5
  • 12
3
votes
1 answer

Zend Framework InArray validator array syntax

My goal is to validate parameters passed in the URL, so I created a validate method that has a list of validators to run, like so: $validators = array( 'number' => array( 'digits', 'presence' => 'required', …
Ian
  • 602
  • 8
  • 12
3
votes
3 answers

Zend_Validator_Regex throws error: Internal error while using the pattern

Message: Internal error while using the pattern "(http://)?(www.)?(youtu)((be.com)|(.be))/.*" $element = new Zend_Form_Element_Text($this->name); $element->setRequired(true) ->setLabel(FileTypes::$names[$this->fileType]) …
divide by zero
  • 2,340
  • 5
  • 23
  • 34
3
votes
4 answers

What regex pattern is the correct to allow just double types?

I have the following code with zend framework: $descuentoElement->addValidator(new Zend_Validate_Regex(array('pattern' => '/[0-9]+(.[0-9]+)?/'))); I want to validate double type inputs like either 1.2 or 4...not "4sd" but instead this pattern…
IJMorgado
  • 137
  • 1
  • 7
1 2
3
14 15