本文整理汇总了PHP中Zend_Form_Element::addValidator方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form_Element::addValidator方法的具体用法?PHP Zend_Form_Element::addValidator怎么用?PHP Zend_Form_Element::addValidator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form_Element
的用法示例。
在下文中一共展示了Zend_Form_Element::addValidator方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupElement
public function setupElement()
{
$element = new Zend_Form_Element('foo');
$element->addValidator('Alnum')->addValidator('Alpha')->setView($this->getView());
$element->isValid('abc-123');
$this->element = $element;
$this->decorator->setElement($element);
}
示例2:
/**
* Creates the registration form and it's elements.
* Also sets the validation techniques for the fields
*/
function __construct()
{
parent::__construct();
$this->setName('Registration');
$this->setMethod('POST');
$this->setAction('/user/register');
$username = new Zend_Form_Element('username');
$username->setLabel('Username');
$username->setRequired(true);
$username->addValidator('NotEmpty', true);
$username->addValidator(new Zend_Validate_StringLength(6, 10), true);
$username->addValidator('Alnum', true);
$username->addValidator(new User_Models_Forms_Validators_IsUnique('username'));
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password');
$password->setRequired(true);
$password->addValidator('NotEmpty', true);
$password->addValidator(new Zend_Validate_StringLength(6, 10));
$gender = new Zend_Form_Element_Select('gender');
$gender->setLabel('Gender');
$gender->setMultiOptions(array('Male' => 'Male', 'Female' => 'Female'));
$email = new Zend_Form_Element_Text('email');
$email->setLabel('Email');
$email->setRequired(true);
$email->addValidator('NotEmpty', true);
$email->addValidator(new User_Models_Forms_Validators_EmailAddress(), true);
$email->addValidator(new User_Models_Forms_Validators_IsUnique('email'));
$paymentEmail = new Zend_Form_Element_Text('paymentEmail');
$paymentEmail->setLabel('Payment Email');
$paymentEmail->setRequired(true);
$paymentEmail->addValidator('NotEmpty', true);
$paymentEmail->addValidator(new User_Models_Forms_Validators_EmailAddress(), true);
$paymentEmail->addValidator(new User_Models_Forms_Validators_IsUnique('paymentEmail'));
$countries = new Zend_Form_Element_Select('country');
$countries->setMultiOptions(self::getCountries());
$countries->setLabel('Country');
$countries->addValidator('NotEmpty');
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Register');
$this->addElements(array($username, $password, $gender, $email, $paymentEmail, $countries, $submit));
}
示例3:
function __construct()
{
parent::__construct();
$this->setName('Registration');
$this->setMethod('POST');
$this->setAction('/user/login');
$username = new Zend_Form_Element('username');
$username->setLabel('Username');
$username->setRequired(true);
$username->addValidator('NotEmpty', true);
$username->addValidator(new Zend_Validate_StringLength(6, 10));
$username->addValidator('Alnum', true);
$password = new Zend_Form_Element_Password('password');
$password->setLabel('Password');
$password->setRequired(true);
$password->addValidator('NotEmpty', true);
$password->addValidator(new Zend_Validate_StringLength(6, 10));
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Register');
$this->addElements(array($username, $password, $submit));
}
示例4: testValidatorsGivenArrayKeysOnValidation
/**
* Check array notation for validators
*/
public function testValidatorsGivenArrayKeysOnValidation()
{
$username = new Zend_Form_Element('username');
$username->addValidator('stringLength', true, array('min' => 5, 'max' => 20, 'ignore' => 'something'));
$form = new Zend_Form(array('elements' => array($username)));
$this->assertTrue($form->isValid(array('username' => 'abcde')));
}
示例5: testGetValidSubFormValues
/**
* @group ZF-8494
*/
public function testGetValidSubFormValues()
{
$data = array('sub' => array('valid' => 1234, 'invalid' => 'invalid', 'noElement' => 'noElement'));
require_once "Zend/Validate/Int.php";
$subForm = new Zend_Form_SubForm();
$validElement = new Zend_Form_Element("valid");
$validElement->addValidator(new Zend_Validate_Int());
$subForm->addElement($validElement);
$invalidElement = new Zend_Form_Element('invalid');
$invalidElement->addValidator(new Zend_Validate_Int());
$subForm->addElement($invalidElement);
$this->form->addSubForm($subForm, 'sub');
$this->assertEquals(array('sub' => array('valid' => 1234)), $this->form->getValidValues($data));
}
示例6: createTaskElement
/**
* Will set up a task-element and decorators
* @param string $id
* @param array $values
* @param array $attribs
* @return Zend_Form_Element
*/
protected function createTaskElement($id, $values, $isNew = false)
{
$elm = new Zend_Form_Element((string) $id);
$elm->clearDecorators();
$elm->addDecorator(new My_Decorator_TaskElement());
$elm->addDecorator('Errors', array('placement' => 'prepend'));
// add configured validator
$validator = new My_Validator_TaskElement();
$validator->setIsNew($isNew);
$elm->addValidator($validator);
return $elm;
}
示例7: testBreakChainOnFailureFlagsForExistingValidatorsRemainSetWhenNotEmptyValidatorAutoInserted
/**
* @see ZF-2862
*/
public function testBreakChainOnFailureFlagsForExistingValidatorsRemainSetWhenNotEmptyValidatorAutoInserted()
{
$this->_checkZf2794();
$username = new Zend_Form_Element('username');
$username->addValidator('stringLength', true, array(5, 20))
->addValidator('regex', true, array('/^[a-zA-Z0-9_]*$/'))
->addFilter('StringToLower')
->setRequired(true);
$form = new Zend_Form(array('elements' => array($username)));
$form->isValid(array('username' => '#'));
$validator = $username->getValidator('stringLength');
$this->assertTrue($validator->zfBreakChainOnFailure);
$validator = $username->getValidator('regex');
$this->assertTrue($validator->zfBreakChainOnFailure);
}
示例8: testValidatorByUsingStringNotation
/**
* @see ZF-6822
*/
public function testValidatorByUsingStringNotation()
{
$this->_checkZf2794();
$username = new Zend_Form_Element('username');
$username->addValidator('stringLength', true, array(5, 20))->addValidator('regex', true, '/^[a-zA-Z0-9_]*$/')->addFilter('StringToLower')->setRequired(true);
$form = new Zend_Form(array('elements' => array($username)));
$form->isValid(array('username' => '#'));
$validator = $username->getValidator('stringLength');
$this->assertTrue($validator->zfBreakChainOnFailure);
$validator = $username->getValidator('regex');
$this->assertTrue($validator->zfBreakChainOnFailure);
}
示例9: applyCustomMessages
/**
* Fügt angepasste Nachrichten für Validierungen hinzu.
* @param Zend_Form_Element $element
*/
protected function applyCustomMessages($element)
{
if ($element->isRequired()) {
// wenn Validator 'notEmpty' bereits gesetzt ist; nicht modifizieren
if (!$element->getValidator('notEmpty') && $element->autoInsertNotEmptyValidator()) {
$notEmptyValidator = new Zend_Validate_NotEmpty();
$notEmptyValidator->setMessage('admin_validate_error_notempty');
$element->addValidator($notEmptyValidator);
}
}
}