diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php index bddc07407..7322537b9 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Form.php @@ -396,13 +396,18 @@ class Form extends AbstractSmartyPlugin $attrFormat = '%s="%s"'; $field = ''; - $instance = $this->getInstanceFromParams($params); + $baseFormInstance = $this->getInstanceFromParams($params); - $formView = $instance->getView(); + $formView = $baseFormInstance->getView(); $return = ""; + /** @var FormView $row */ foreach ($formView->getIterator() as $row) { + + // We have to exclude the fields for which value is defined in the template. + if ($baseFormInstance->isTemplateDefinedHiddenField($row)) continue; + if ($this->isHidden($row) && $row->isRendered() === false) { $attributeList = array(); if (isset($row->vars["attr"])) { diff --git a/core/lib/Thelia/Form/BaseForm.php b/core/lib/Thelia/Form/BaseForm.php index cea9bbba7..716c08ff8 100644 --- a/core/lib/Thelia/Form/BaseForm.php +++ b/core/lib/Thelia/Form/BaseForm.php @@ -12,12 +12,13 @@ namespace Thelia\Form; -use Symfony\Component\Form\Extension\Validator\ValidatorExtension; -use Symfony\Component\Form\Forms; -use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension; use Symfony\Component\Form\Extension\Csrf\CsrfExtension; use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider; +use Symfony\Component\Form\Extension\HttpFoundation\HttpFoundationExtension; +use Symfony\Component\Form\Extension\Validator\ValidatorExtension; +use Symfony\Component\Form\Forms; +use Symfony\Component\Form\FormView; +use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Validator\Validation; use Thelia\Core\Translation\Translator; use Thelia\Model\ConfigQuery; @@ -95,17 +96,38 @@ abstract class BaseForm $this->buildForm(); // If not already set, define the success_url field + // This field is not included in the standard form hidden fields + // This field is not included in the hidden fields generated by form_hidden_fields Smarty function if (! $this->formBuilder->has('success_url')) { $this->formBuilder->add("success_url", "hidden"); } + // The "error_message" field defines the error message displayed if + // the form could not be validated. If it is empty, a standard error message is displayed instead. + // This field is not included in the hidden fields generated by form_hidden_fields Smarty function if (! $this->formBuilder->has('error_message')) { - $this->formBuilder->add("error_message", "text"); + $this->formBuilder->add("error_message", "hidden"); } $this->form = $this->formBuilder->getForm(); } + /** + * Return true if the given field value is defined only in the HTML template, and its value is defined + * in the template file, not the form builder. + * Thus, it should not be included in the form hidden fields generated by form_hidden_fields + * Smarty function, to prevent it from exiting twice in the form. + * + * @param FormView $fieldView + * @return bool + */ + public function isTemplateDefinedHiddenField($fieldView) { + $name = $fieldView->vars['name']; + + return $name == 'success_url' || $name == 'error_message'; + } + + public function getRequest() { return $this->request; @@ -146,6 +168,10 @@ abstract class BaseForm return $this; } + /** + * @return FormView + * @throws \LogicException + */ public function getView() { if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first.");