Я пытаюсь проверить форму в самой фактической форме, но она вообще не проверяется. Если я наберу «someemail & *! ([] @ Gmail.com», он действительно не дает дерьма и не движется дальше. Форма:
class RecoverPasswordForm extends Form { public function __construct($options = null) { parent::__construct("RecoverPassword"); $username = new Element("username"); $username->setLabel("Email"); $username->setAttributes( array('filters' => array( array('name' => 'StringTrim'), array('name' => 'StripTags')), 'validators' => array( array( 'name' => 'Regex', 'options' => array( 'pattern' => '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/', 'messages' => array( Regex::NOT_MATCH => 'The email your provided has invalid characters.', ), ), 'break_chain_on_failure' => true ), array( 'name' => 'EmailAddress', 'options' => array( 'messages' => array( EmailAddress::INVALID_FORMAT => "Email address is invalid", EmailAddress::INVALID => "", EmailAddress::INVALID_LOCAL_PART => "", EmailAddress::INVALID_HOSTNAME => "", EmailAddress::INVALID_SEGMENT => "", EmailAddress::DOT_ATOM => "", EmailAddress::INVALID_MX_RECORD => "", ), ), ), ), 'label' => 'Email')); $this->add(array( $username, )); } }
Как я получаю (или пытаюсь получить) фильтры и валидаторы в контроллере:
public function recoverPasswordAction() { $this->cache = new Container("cache"); $request = $this->getRequest(); $form = new RecoverPasswordForm(); // $form->get("submit")->setValue("Send mail"); $this->view->form = $form; if ($request->isPost()) { $user = new User(); $form->getInputFilter()->getValues(); $form->setInputFilter($form->getInputFilter()); $data = $request->getPost(); $form->setData($data); $username = $data['username']; $userData = $this->getServiceLocator()->get("UserTable")->fetchList("`username` LIKE '$username'"); if (!count($userData) > 0) { $this->cache->error = "A user with this email does not exist, plese try again."; } if ($form->isValid()) { foreach ($userData as $user) { $user->sendMail(6); $this->cache->success = "A message has been send to this email, containing your password."; } } } return $this->view; }