I'm using Phalcon 3.4 with Micro application. I've a simple form:
class LoginForm extends Base {
public function initialize() {
$field = new Text('email');
$field->addValidators([
new PresenceOf(),
new Email([ 'allowEmpty' => TRUE ]),
new StringLength([ 'max' => 255 ]),
]);
$this->add($field);
}
}
Form validation is executed like stated in documentation. The controller action looks like:
$form = new LoginForm();
if ($this->request->isPost()) {
if ($form->isValid($this->request->getPost())) {
[...]
}
}
All is fine so far. But when I'm sending a manipulated POST request to my app intentionally, i.e.:
email[][email protected]
Then email
would be parsed as array in PHP, so form validation fails and I get an error:
<b>WARNING:</b> mb_strlen() expects parameter 1 to be string, array given in [...]
This error is triggered on line $form->isValid(...)
definitely. Whoa!? How can I prevent such behavior?
EDIT 2019-04-20: Added missing StringLength
validator to sample code