开发者

Zend_Form custom error messages

class Form_A开发者_开发技巧ccounts_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));
    }

}

If the email isn't valid, I get: emailAddressInvalidHostname for $form->getErrors('email');

I would like to customize that error, is it possible?


This is just an example. This might help you.....

$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.");
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜