2008年11月24日星期一

Re: [fw-mvc] Form Validation Messages

Matthew Weier O'Phinney-3 wrote:
>
> I'd do this:
>
> $this->setRequired(true)
> ->addValidators(array(
> array('NotEmpty', true, array('messages' => array(
> 'isEmpty' => 'Please enter a password.',
> ))),
> 'Alnum',
> array('StringLength', false, array(4, 20)),
> ))
> ->addFilter('StringToLower');
>
> Hope that makes sense!
>

um, only just. as in it works, but i don't really get whats happening.

to add different messages for blank or invalid email addresses, i did this:

$email->setRequired(true)
->addValidators(array(
array('NotEmpty', true, array('messages' => array(
'isEmpty' => 'You must enter an email, or else.',
))),
'EmailAddress',
array('EmailAddress', false, array('messages' => array(
'emailAddressInvalid' => 'An actual email address would be
awesome.'))),
))
;

I don't know what the true / false second parameters do? i changed the
second one to false and it dosn't change the behaviour.

This seems a bit hard to use, so i tried doing it differently:

$validator = new Zend_Validate_NotEmpty();
$validator->setMessage('You must enter an Email address.');
$email->addValidator($validator);
$validator = new Zend_Validate_EmailAddress();
$validator->setMessage('You must enter a valid Email
address.',Zend_Validate_EmailAddress::INVALID);
$email->addValidator($validator);

which dosn't throw an error, but then dosn't trap empty or invalid emails
either. Do i have to set a 'break chain on error' boolean, and if so, where?

Finaly, is there a better way to set the default error messages than in the
zend framework validate clases?

--
View this message in context: http://www.nabble.com/Form-Validation-Messages-tp15351486p20671445.html
Sent from the Zend MVC mailing list archive at Nabble.com.

没有评论: