zend-validate

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 value. $nameField = new Zend_Form_Element_Hidden('namefield'); $nameField->setValue($this->nameField...

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) ->addValidator('OnlyOneHasValue', false, array(array('textFieldTwo', 'textFieldThree'...

How can I output HTML from a Zend Validation Error?

I am trying to get this Zend Validator to output a link that goes to a resetpass form. At the moment, it is simply outputting the HTML as text. Any ideas on how to get it writing to the page as HTML? Thanks! Here's my code: protected $_authAdapter; protected $_messageTemplates = array( self::NOT_UNIQUE => 'This email has alre...

How to validate >1 field at a time, in a Zend sub-form?

I've created a 3 screen "wizard" using the Zend_Form_SubForm example from the online reference documentation. The requirement I'm having trouble meeting is this: If fields 1, 2, & 3 of the first screen are already in the database, notify the user that they are trying to add a duplicate record. Each of those fields has their own validato...

In a Zend_Form, how to avoid Zend_Validate_Email from generating multiple errors?

I am building a ZendFramework application which as a login form asking for an email address and password - it seemed to make sense to validate the email address before hitting the database with the login attempt, as an invalid email would never lead to a valid hit. Zend_Validate_EmailAddress seemed like the right way to go, but I am havi...

To add validation GreaterThan - Zend Form

<?php class Form_Audience extends Zend_Form_SubForm { public function init() { $this->setMethod('post'); $this->setLegend('Audience Details'); $this->addElement('text', 'audience_total', array( 'label' => 'Audience Total :', 'required' => true, 'filters' => ar...

validating YYYY-MM-DD formatted strings with Zend_Validate_Date in en_US locale

I'm validating user entered date string in YYYY-MM-DD format using Zend_Validate::is($value,'Date'). this call causes this hierarchy: Zend_Validate::is() Zend_Validate_Date->isValid() Zend_Date::isDate() Zend_Locale_Format::getDate() Zend_Locale_Format::_parseDate() and then fials with this exception: Zend_Locale_Exception: Unable t...

Zend Framework and string covertation using iconv

Hello, everyone One site was moved to another server where is installed Solaris and other iconv settings. Now, when I validate anythink with "StringLength" function from Zend Framework my scripts fail with this error: Notice: iconv_strlen() [function.iconv-strlen]: Wrong charset, conversion from `UTF-8' to `UCS-4LE' is not allowed in /...

Zend Db_NoRecordExists - checking against multiple columns

Hi, 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 validator: $email->setValidators(array(array('emailAddress'), array('Db_NoRecordExis...

How to validate multidimensional array in Zend ?

Hello ! I am wondering what is the best way to validate multidimensional array using Zend_Validate with Zend_FilterInput. Here is my current code: $filters = array( 'symbol' => array('StripTags', 'StringTrim'), 'mode' => array('StripTags', 'StringTrim'), ); $validators = array( 'symbol' => array('N...

Zend Form Edit and Zend_Validate_Db_NoRecordExists

I am slowly building up my Zend skills by building some utility websites for my own use. I have been using Zend Forms and Form validation and so far have been happy that I have been understanding the Zend way of doing things. However I am a bit confused with how to use Zend_Validate_Db_NoRecordExists() in the context of an edit form an...

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 following does not work: $dateValidator = new Zend_Validate_Date('yyyy-MM-dd hh:ii'); I...

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 element is in a date format. How do I determine that the date given is greater than or equal...

having problems with Zend framework validators

Hello! I'm having problem with custom builded validator that does not returns any error. I copied a file NotEmpty.php form folder library/Zend/Validate, rename class Zend_Validate_NotEmpty to My_Validate_EmailConfirmation and put it into folder My/Validate. If I call this class like ->setRequired(true)->addValidator('NotEmpty',true,arr...

Zend Form validator is not triggered

Hello Everyone, I am trying to get my UniqueEmail validator working but it seems that my validator is never triggered. This is my form: class EventManager_Form_User_Base extends SF_Form_Abstract{ public function init(){ $this->addElementPrefixPath( 'EventManager_Validate', APPLICATION_PATH . '/modules/eventManage...

Recommended place for pre-translated Zend Framework resources

Since zf 1.10 Zend Framework ships with pre-translated validation messages. They are outside the library path. The manual illustrates how to load these in your bootstrap. $translator = new Zend_Translate( 'array', '/resources/languages', $language, array('scan' => Zend_Locale::LOCALE_DIRECTORY) ); Zend_Validate_Abstra...

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' => array($requiredBasedOnCountry), 'filters' => array($makeZeroNull))); The reason I am doing this is beca...

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 it to (for example: "Please enter a valid email"). Is there any way of doing it elegantly...

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 value will not be in the $context array for the element in the Third SubForm. What is a sens...

How to use Zend_Validate_File_MimeType() ??

Hello friends, I´m trying to use the zend mime validator and I´m doing this: $mime = array('image/jpeg','image/gif'); $valid = new Zend_Validate_File_MimeType($mime); if ($valid->isValid($_FILES['file']['name']){ // do some stuff } But it not working, the documentation is weak, how can I use it??! THanks and best regard´s! ...