/**
  * 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. ") . $this->translator->trans("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));
             }
             $aBaseForm->setError(true);
             throw new FormValidationException($errorMessage);
         }
     } else {
         throw new FormValidationException(sprintf($this->translator->trans("Wrong form method, %s expected."), $expectedMethod));
     }
 }
Example #2
0
 /**
  * If success_url param is present in request or in the provided form, redirect to this URL.
  *
  * @param BaseForm $form a base form, which may contains the success URL
  *
  * @deprecated redirectSuccess is deprecated since version 2.1 and will be removed in 2.3. You must return an instance of \Symfony\Component\HttpFoundation\RedirectResponse insteand of send a response.
  * @see generateSuccessRedirect instead of this method
  */
 protected function redirectSuccess(BaseForm $form = null)
 {
     trigger_error('redirectSuccess is deprecated since version 2.1 and will be removed in 2.3. You must return an instance of \\Symfony\\Component\\HttpFoundation\\RedirectResponse insteand of send a response. ', E_USER_DEPRECATED);
     if ($form != null) {
         $url = $form->getSuccessUrl();
     } else {
         $url = $this->getRequest()->get("success_url");
     }
     if (null !== $url) {
         $this->redirect($url);
     }
 }
Example #3
0
 /**
  * Setup the error context when an error occurs in a action method.
  *
  * @param string     $action        the action that caused the error (category modification, variable creation, currency update, etc.)
  * @param BaseForm   $form          the form where the error occured, or null if no form was involved
  * @param string     $error_message the error message
  * @param \Exception $exception     the exception or null if no exception
  */
 protected function setupFormErrorContext($action, $error_message, BaseForm $form = null, \Exception $exception = null)
 {
     if ($error_message !== false) {
         // Log the error message
         Tlog::getInstance()->error($this->getTranslator()->trans("Error during %action process : %error. Exception was %exc", array('%action' => $action, '%error' => $error_message, '%exc' => $exception != null ? $exception->getMessage() : 'no exception')));
         if ($form != null) {
             // Mark the form as errored
             $form->setErrorMessage($error_message);
             // Pass it to the parser context
             $this->getParserContext()->addForm($form);
         }
         // Pass the error message to the parser.
         $this->getParserContext()->setGeneralError($error_message);
     }
 }
 public function __construct(Request $request, $type = "form", $data = array(), $options = array(), ContainerInterface $container = null)
 {
     $this->data = $data;
     parent::__construct($request, $type, $data, $options, $container);
     // TODO: Change the autogenerated stub
 }
Example #5
0
 public function __construct(Request $request, $type = "form", $data = array(), $options = array())
 {
     $this->taxEngine = $options["tax_engine"];
     unset($options["tax_engine"]);
     parent::__construct($request, $type, $data, $options);
 }
Example #6
0
 /**
  * @param $collection
  * @param BaseForm $form
  * @return SymfonyForm
  *
  * Extract the collection object from the form
  */
 protected function resolveCollection($collection, BaseForm $form)
 {
     if (null === $collection) {
         throw new \InvalidArgumentException("Missing parameter 'collection' in 'form_collection");
     }
     $sfForm = $form->getForm();
     if (!$sfForm->has($collection)) {
         throw new \InvalidArgumentException(sprintf("Field name '%s' not found in form %s children", $collection, $form->getName()));
     }
     /**
      * Check that the field is a "collection" type
      */
     $collectionConfig = $this->retrieveField($collection, $sfForm->all(), $form->getName());
     $fieldType = $collectionConfig->getConfig()->getType();
     if ($fieldType->getName() !== static::COLLECTION_TYPE_NAME) {
         $baseFieldType = $fieldType;
         $resolved = false;
         while (null !== $fieldType && !$resolved) {
             if ($fieldType->getName() !== static::COLLECTION_TYPE_NAME) {
                 $fieldType = $fieldType->getParent();
             }
         }
         if (!$resolved) {
             throw new \LogicException(sprintf("The field '%s' is not a collection, it's a '%s'." . "You can't use it with the function 'form_collection' in form '%s'", $collection, $baseFieldType->getName(), $form->getName()));
         }
     }
     return $collectionConfig;
 }
 /**
  * Search url in a form parameter, or in a request parameter.
  *
  * @param  string $parameterName the form parameter name, or request parameter name.
  * @param  BaseForm  $form the form
  * @return mixed|null|string
  */
 protected function retrieveFormBasedUrl($parameterName, BaseForm $form = null)
 {
     $url = null;
     if ($form != null) {
         $url = $form->getFormDefinedUrl($parameterName);
     } else {
         $url = $this->container->get('request_stack')->getCurrentRequest()->get($parameterName);
     }
     return $url;
 }
Example #8
0
 public function getName()
 {
     return $this->form->getName();
 }
Example #9
0
 public function __construct(Request $request, $type = "form", $data = array(), $options = array())
 {
     $this->translator = Translator::getInstance();
     parent::__construct($request, $type, $data, $options);
     // TODO: Change the autogenerated stub
 }
 /**
  * @param BaseForm $form
  * @param string $successMessage
  * @param string $errorMessage
  * @return \Thelia\Core\HttpFoundation\Response
  */
 protected function renderAdminConfig($form, $successMessage, $errorMessage)
 {
     if (!empty($errorMessage)) {
         $form->setErrorMessage($errorMessage);
         $this->getParserContext()->addForm($form)->setGeneralError($errorMessage);
     }
     //for compatibility 2.0
     if (method_exists($this->getSession(), "getFlashBag")) {
         if (empty($errorMessage)) {
             $this->getSession()->getFlashBag()->add("success", $successMessage);
         } else {
             $this->getSession()->getFlashBag()->add("danger", $errorMessage);
         }
     }
     return RedirectResponse::create(URL::getInstance()->absoluteUrl("/admin/module/CustomerFamily"));
 }
Example #11
0
 public function __construct(Request $request, $type = "form", $data = array(), $options = array(), TaxEngine $taxEngine = null)
 {
     $this->taxEngine = $taxEngine;
     parent::__construct($request, $type, $data, $options);
 }
Example #12
0
 public function __construct(Request $request, $type = "form", $data = array(), $options = array())
 {
     $this->translator = Translator::getInstance();
     parent::__construct($request, $type, $data, $options);
 }