本文整理汇总了PHP中FormElement::addValidator方法的典型用法代码示例。如果您正苦于以下问题:PHP FormElement::addValidator方法的具体用法?PHP FormElement::addValidator怎么用?PHP FormElement::addValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类FormElement
的用法示例。
在下文中一共展示了FormElement::addValidator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addFieldValidator
/**
* Set field validator
*
* @param FormElement $formField
* @param array $question
*/
protected function addFieldValidator($formField, $question)
{
if ((string) $question['base'] === '1') {
if ($question['name'] === 'email') {
$formField->addValidator(new editEmailValidator($this->userId));
} else {
if ($question['name'] === 'username') {
$formField->addValidator(new editUserNameValidator($this->userId));
}
}
}
return $formField;
}
示例2: addValidator
public function addValidator($validator)
{
if ($validator instanceof CaptchaValidator) {
$validator->setJsObjectName($this->jsObjectName);
}
return parent::addValidator($validator);
}
示例3: setValidators
/**
* Binds FormValidators to a FormElement field
*
* accepts an array in this format :
* array('fieldName' => array(
* 0 => array(
* 'class' => 'validatorClass',
* 'options' => array('key' => 'value')
* ),
* 1 => array(
* 'class' => 'validatorClass',
* 'options' => array('key' => 'value')
* ),
* )
* );
*/
public function setValidators(FormElement $element, array $validators)
{
foreach ($validators as $field => $validations) {
if ($field === $element->getName()) {
foreach ($validations as $validation) {
$classname = $validation['class'] . 'FormElementValidator';
if (!class_exists($classname)) {
throw new FormException('Validation classname "' . $classname . '" should be a valid validator class');
}
$validator = new $classname($element);
if (isset($validation['options']) && is_array($validation['options']) && count($validation['options'])) {
$validator->setOptions($validation['options']);
}
$element->addValidator($validator);
}
}
}
}