Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Zend_表单自定义错误消息_Php_Zend Framework_Zend Form - Fatal编程技术网

Php Zend_表单自定义错误消息

Php Zend_表单自定义错误消息,php,zend-framework,zend-form,Php,Zend Framework,Zend Form,如果电子邮件无效,我会得到:emailAddressInvalidHostname for$form->getErrors('email') 我想自定义该错误,可能吗?这只是一个示例。这可能会帮助你 class Form_Accounts_Add extends Zend_Form { public function init($options=array()) { $first_name = new Zend_Form_Element_Text('firs

如果电子邮件无效,我会得到:emailAddressInvalidHostname for$form->getErrors('email')


我想自定义该错误,可能吗?

这只是一个示例。这可能会帮助你

class Form_Accounts_Add extends Zend_Form {


    public function init($options=array()) {

        $first_name     = new Zend_Form_Element_Text('first_name');
        $last_name      = new Zend_Form_Element_Text('last_name');
        $email          = new Zend_Form_Element_Text('email');
        $password       = new Zend_Form_Element_Text('encrypted_password'); 

        $first_name->setRequired(false);
        $last_name->setRequired(false);
        $email->setRequired(true)->addFilter('StringToLower')->addValidator('NotEmpty', true)->addValidator('EmailAddress');
        $password->setRequired(true);

        $this->addElements(array($first_name, $last_name, $email, $password));
    }

}

好的,当然,我已经投了赞成票,但没有滴答作响,浏览了我的8页并正确地获得了奖励。谢谢这对我来说对alnum验证器不起作用。在我的Zend_Form类中,我正在执行$this->addElement(…),我将validators部分从'validators'=>array('alnum')更改为'validators'=>array(array('alnum',true,array('messages'=>array('notAlnum'=>custommessage'))
$email = new Zend_Form_Element_Text('emailid');

$email->setLabel("Email-Adress :* ")
      ->setOptions(array('size' => 20))
      ->setRequired(true)
      ->addFilter('StripTags')
      ->addFilter('StringTrim')
      ->addValidator('EmailAddress')
      ->getValidator('EmailAddress')->setMessage("Please enter a valid e-mail address.");