/** * Validate a BaseForm * * @param BaseForm $aBaseForm the form * @param string $expectedMethod the expected method, POST or GET, or null for any of them * @throws FormValidationException is the form contains error, or the method is not the right one * @return \Symfony\Component\Form\Form Form the symfony form object */ public function validateForm(BaseForm $aBaseForm, $expectedMethod = null) { $form = $aBaseForm->getForm(); if ($expectedMethod == null || $aBaseForm->getRequest()->isMethod($expectedMethod)) { $form->handleRequest($aBaseForm->getRequest()); if ($form->isValid()) { if ($aBaseForm instanceof FirewallForm && !$aBaseForm->isFirewallOk($this->environment)) { throw new FormValidationException($this->translator->trans("You've submitted this form too many times. " . "Further submissions will be ignored during %time", ["%time" => $aBaseForm->getWaitingTime()])); } return $form; } else { $errorMessage = null; if ($form->get("error_message")->getData() != null) { $errorMessage = $form->get("error_message")->getData(); } else { $errorMessage = sprintf($this->translator->trans("Missing or invalid data: %s"), $this->getErrorMessages($form)); } throw new FormValidationException($errorMessage); } } else { throw new FormValidationException(sprintf($this->translator->trans("Wrong form method, %s expected."), $expectedMethod)); } }