本文整理汇总了PHP中Zend_Form_Element::getValidator方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Form_Element::getValidator方法的具体用法?PHP Zend_Form_Element::getValidator怎么用?PHP Zend_Form_Element::getValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Form_Element
的用法示例。
在下文中一共展示了Zend_Form_Element::getValidator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setupSingleElement
/**
* Setup per-element properties like labels, and classes
*/
protected function setupSingleElement(Zend_Form_Element $elm)
{
// determine if this element has an error. (Will be used below)
$elmHasError = count($elm->getMessages()) > 0;
// set element values from the language pack
$elm->setLabel($this->lang->get('form.label.' . $elm->getName()));
// display info about required length if validator exists
if ($elm->getValidator('StringLength')) {
$elm->setDescription(sprintf($this->lang->get('form.description.' . $elm->getName()), $elm->getValidator('StringLength')->getMin(), $elm->getValidator('StringLength')->getMax()));
} else {
$elm->setDescription($this->lang->get('form.description.' . $elm->getName()));
}
// Duplicating type attr to classname in case we need to support IE6
// and want to be able to directly target the element without using
// input[type=text]
$zendType = $elm->getType();
$className = strtolower(substr($zendType, strrpos($zendType, '_') + 1));
$elm->setAttrib('class', $className);
// wrap this stuff up in a html div with class 'element'
$elm->addDecorator('HtmlTag', array('tag' => 'div', 'class' => 'element'));
// determine if element has error and use that to determine prefix char.
// 1. There seems to be no way to add html to the reqPrefix
// 2. There seems to be no way to add a custom classname to the div tag
if ($elm->getName() != 'submit') {
$reqChar = $elmHasError ? '! ' : '* ';
$elm->addDecorator('Label', array('placement' => 'prepend', 'tag' => 'div', 'requiredPrefix' => $reqChar));
}
// use custom error decorator that attempts to replace default error
// messages by the ones supplied by My_LanguagaPack
$errorDecorator = new My_Decorator_Errors();
$errorDecorator->setLanguagePack($this->lang);
$elm->addDecorator($errorDecorator);
// wrap everything so far in a li tag, give it class error if elm has error
// ATT: using array to create alias for allready used HtmlTag decorator
$liClass = $elmHasError ? 'error' : '';
$elm->addDecorator(array('outerLi' => 'HtmlTag'), array('tag' => 'li', 'class' => $liClass));
}
示例2: 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);
}
示例3: 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);
}
示例4: 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);
}
}
}