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

Why is my Zend Validate Digits not recognised?

I'm creating a form with the Zend Framework to capture user demographics. I'm struggling with validation for digits on two text fields. I build my form in ../application/forms/UserDemographics.php like this: class Application_Form_UserDemographics…
marienke
  • 2,465
  • 4
  • 34
  • 66
3
votes
3 answers

How to add required error message to my input in Zend Framework 1.11?

I have the following code snippets in my forms/video.php. But i do not know where to add the validation message for required. $this->addElement('text','name', array( 'label'=>'Name', 'maxlength'=>20, 'class'=>'name', …
2
votes
2 answers

How to validate a element based on another element's value?

I have a Client ID, and a Unique Client hash. When I register these data, it works fine. Just to be clear, I do not generate the hash. The code I use to validate if that unique hash already exists: protected function _getValidator($field) { …
Denis Lins
  • 816
  • 7
  • 22
2
votes
2 answers

Zend Validate - Multiple Values

I want to validate a form element that is allowed to contain multiple email addresses, separated by a comma and a space. Here's the code I have: class My_Validate_EmailAddresses extends Zend_Validate_Abstract { const MSG_INVALID =…
Sonny
  • 8,204
  • 7
  • 63
  • 134
2
votes
2 answers

How does one create a validator that depends on more than one value for Zend_Form?

I've got a form that has a single text field (for company): class Cas_Form_Company extends Zend_Form { public function init() { $this->addElement('hidden', 'id'); $this->addElement('text', 'name', array('label' => 'Name')); …
Billy ONeal
  • 104,103
  • 58
  • 317
  • 552
2
votes
4 answers

Zend EmailAddress Validation returning multiple errors

I am unable to make Zend_Validate_EmailAddress show only 1 error message when the user enter invalid email address. The code is $email = new Zend_Form_Element_Text('email'); $email->setLabel('Email: ') ->addFilter('StringTrim') …
Bryan
  • 645
  • 1
  • 6
  • 18
2
votes
1 answer

Zend_form: doesn't accept Latin characters(ú, ë, etc?

I can't get Zend_form to accept any inserted latin characters (ü, é, etc). Even if I'm not validating it doesn't accept this. Does anyone now how to get this to work? Gr. Tosh
Tosh
  • 1,789
  • 15
  • 20
2
votes
2 answers

Validate an input field for a date through Zend_Form with Zend_Validate_Date

$this->addElement('text', 'projected-start', array( 'required' => false, 'validators' => array ( array('date', false, array('MM/dd/yyyy')) ), 'label' => 'Projected Start:', 'class' …
user434366
  • 539
  • 7
  • 15
2
votes
1 answer

How should Zend_Validator_StringLength extended?

How should Zend_Validator_StringLength extended? MyValidator: class Zend_Validate_StringLengthNoTags extends Zend_Validate_StringLength { public function __construct($options = array()) { parent::__construct($options); } …
Ben
  • 25,389
  • 34
  • 109
  • 165
2
votes
2 answers

Reusing Zend validators on client-side

I found this question on another forum where it didn't get any answers. I thought it was a good question worth asking here. I'm pasting it here word for word. Hi guys, I've got a pie in the sky idea, and I'm just wondering if it's even…
jblue
  • 4,390
  • 4
  • 46
  • 79
2
votes
1 answer

ZF2 + Doctrine2 - Fieldset in Fieldset of a Collection in Fieldset does not validate properly

I asked a similar question a while ago, which came down to the structuring of the Forms, Fieldsets and InputFilters. I've been thoroughly applying the principle of separation of concerns to split up Fieldsets from InputFilters as the modules…
rkeet
  • 3,406
  • 2
  • 23
  • 49
2
votes
1 answer

Zend Validate - How do you pass context values from a different subform?

I've split up a Form into 3 SubForms and for one of the elements, in the last SubForm, I am creating a Validator that extends Zend_Validator_Abstract. This validator needs to check that a value, on the second SubForm, is not empty. However this…
gawpertron
  • 1,867
  • 3
  • 21
  • 37
2
votes
1 answer

Validator\Db\RecordExists with multiple columns

ZF2 docs show the following example in terms of using Db\RecordExists validator with multiple columns. $email = 'user@example.com'; $clause = $dbAdapter->quoteIdentifier('email') . ' = ' . $dbAdapter->quoteValue($email); $validator = new…
Rob
  • 1,158
  • 1
  • 12
  • 22
2
votes
3 answers

Validate with Zend_Validate_Date on a time string

Hey all I'm trying to validate a 'time' field using Zend Framework. The docs seem to be pointing out that the following: $tstarttime = $form->createElement('text','t_start_time'); $tstarttime->setRequired(true) ->setLabel('Start Time') …
remedix
  • 492
  • 6
  • 13
2
votes
1 answer

Zend Validate, Display one message per validator

I am validating an email address using zend_validate_email. For example, for email address aa@aa it throws several error messages including very technical describing that DNS mismatch (:S). I am trying to make it display only 1 message that I want…
iBiryukov
  • 1,730
  • 4
  • 19
  • 30