public function afterFormValidate(FormEvent $event, $name, EventDispatcherInterface $dispatcher) { $form = $event->getForm(); if (!$form->isValid() || (string) $form->getRow($this->form_field)->getValue() === '') { return; } $form->addTag(self::CAUGHT); $honeypot_event = new HoneypotEvent($form, $this->form_field); $dispatcher->dispatch(self::CAUGHT, $honeypot_event); if ($this->throw_exception) { throw new HoneypotException(sprintf('Honeypot field "%s" tripped on form "%s"', $this->form_field, $form->getId())); } }
public function afterFormValidate(FormEvent $event, $name, EventDispatcherInterface $dispatcher) { $form = $event->getForm(); if (!$form->isValid()) { return; } $id = $form->getId(); $input = $form->getRow($this->form_field); $token = $input->getValue(); if ($this->checker->check($id, $token)) { //the token is valid and is now removed. Generate a new token //in case the form needs to be submitted again. $input->setValue($this->checker->init($id)); return; } $form->addTag(CsrfListener::INVALID); $csrf_event = new CsrfEvent($form, $this->form_field); $dispatcher->dispatch(CsrfListener::INVALID, $csrf_event); if ($this->throw_exception) { throw new CsrfTokenException(sprintf('Csrf field "%s" on form "%s" is invalid.', $this->form_field, $form->getId())); } }