Hi to everyone, i've just started a new project with Zend Framework (very
cool), i want to submit a question about Zend_Form usage.
I created a custom subclass of Zend_Form to enclose all common code shared
by different forms and then for every form I need, I subclass this custom
class adding elements and validators. Now I have two problems, one with
filters and one very frustrating with validators. This is the constructor of
first form (the parent form of every other):
public function __construct($options = null) {
parent::__construct($options);
// set class for this form
$this->setAttrib('class', 'zenitspotform');
// set the form to be post
$this->setMethod('post');
// trim all values provided in form
$this->setElementFilters(array ('StringTrim'));
// set translator
$this->setTranslator(
Zend_Registry::get('translator')->getAdapter());
}
and this is an example form constructor (with only one field but in the
others, with more fields, the behaviour is the same)
public function __construct($options = null) {
parent::__construct($options);
$this->addElement('text', 'login',
array ('label' => 'Username (e-mail)'));
$this->login->setRequired(true);
$this->login->addValidator('Date', true);
$this->login->addValidator('Digits', true);
$this->login->addValidator('Alpha', true);
/* this method add a submit button */
$this->addSubmitButton('Send >>');
}
If I insert the value ' qwerty ' (without quotes, please note the blanks at
the begin and at the end of the string) I obtain these errors:
* ' qwerty ' is not of the format YYYY-MM-DD
* ' qwerty ' contains not only digit characters
* ' qwerty ' has not only alphabetic characters
Now the problems:
1) Why StringTrim filter is not applied to submitted value? I expect as
output the value 'qwerty', but blanks remains in the result...
2) Why all validators are executed???? I passed true as second parameter of
every addValidator call, so I expect only the date validator should be
processed.
Two other strange thing, if I remove the setRequired line, only the first
validator is being executed and the other two don't show their error
message. As a other solution If I add a NotEmpty validator, I obtain the
same result...
Can anyone explain me this behaviour, i'm going crazy!!!
Thanks.
--
View this message in context:
http://www.nabble.com/Zend_Form-bug-or-am-I-stupid--tp16019346s16154p16019346.html
Sent from the Zend Framework mailing list archive at Nabble.com.