I am trying to get the Zend_Filter_Input to work as required on a simple login form.
Here is my code
$filters = array('username' => 'StringTrim', 'password' => 'StringTrim');
$validators = array(
'username' => array('Alnum', 'presence' => 'required'),
'password' => array('Alnum', 'presence' => 'required')
);
$input = new Zend_Filter_Input($filters,$validators);
print_r($input->getMissing());
and the response is this
Array
(
[username] => Array
(
[0] => Field 'username' is required by rule 'username', but the field is missing
)
[password] => Array
(
[0] => Field 'password' is required by rule 'password', but the field is missing
)
)
I am referred to the official docs. Why is it saying rule "username" and rule "password" here ?
Thanks
I’m the developer who designed and implemented Zend_Filter_Input in 2007.
Each rule is identified by the associative array key. In your case you have two rules, “username” and “password”. If your input does not pass some of your rules, the error messages tell you which rules were not satisfied.
Your rule names also happen to correspond to the names of the form fields you’re validating. By default, the field that a rule validates is the same as the rule name.
Re your comment: You aren’t passing $_POST as data to validate. You must do either this:
Or else this: