// class TestForm extends Form
// ...
$email = new Text('email');
$email->setLabel('Email');
$email->setFilters(['trim', 'email']); // <-- Filter
$email->addValidator(new Email(array(
'message' => 'Email entered is not in a valid format.'
)));
$this->add($email);
In the controller checking validity
$req = $this->request;
if ($req->isPost() && $form->isValid($req->getPost())) {
// aa([email protected])@cc.com, validation error triggered
// aa(bb)@cc.com validation not triggered, filtered
// If $email->setFilters(['trim', 'email']); were commented out
// aa(bb)@cc.com, validation error triggered
When $_POST
is bind()
to model entity, the model property will get the filtered result.