Fixed "success_url" appearing twice in forms
This commit is contained in:
@@ -396,13 +396,18 @@ class Form extends AbstractSmartyPlugin
|
|||||||
$attrFormat = '%s="%s"';
|
$attrFormat = '%s="%s"';
|
||||||
$field = '<input type="hidden" name="%s" value="%s" %s>';
|
$field = '<input type="hidden" name="%s" value="%s" %s>';
|
||||||
|
|
||||||
$instance = $this->getInstanceFromParams($params);
|
$baseFormInstance = $this->getInstanceFromParams($params);
|
||||||
|
|
||||||
$formView = $instance->getView();
|
$formView = $baseFormInstance->getView();
|
||||||
|
|
||||||
$return = "";
|
$return = "";
|
||||||
|
|
||||||
|
/** @var FormView $row */
|
||||||
foreach ($formView->getIterator() as $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) {
|
if ($this->isHidden($row) && $row->isRendered() === false) {
|
||||||
$attributeList = array();
|
$attributeList = array();
|
||||||
if (isset($row->vars["attr"])) {
|
if (isset($row->vars["attr"])) {
|
||||||
|
|||||||
@@ -12,12 +12,13 @@
|
|||||||
|
|
||||||
namespace Thelia\Form;
|
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\CsrfExtension;
|
||||||
use Symfony\Component\Form\Extension\Csrf\CsrfProvider\SessionCsrfProvider;
|
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 Symfony\Component\Validator\Validation;
|
||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
@@ -95,17 +96,38 @@ abstract class BaseForm
|
|||||||
$this->buildForm();
|
$this->buildForm();
|
||||||
|
|
||||||
// If not already set, define the success_url field
|
// 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')) {
|
if (! $this->formBuilder->has('success_url')) {
|
||||||
$this->formBuilder->add("success_url", "hidden");
|
$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')) {
|
if (! $this->formBuilder->has('error_message')) {
|
||||||
$this->formBuilder->add("error_message", "text");
|
$this->formBuilder->add("error_message", "hidden");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->form = $this->formBuilder->getForm();
|
$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()
|
public function getRequest()
|
||||||
{
|
{
|
||||||
return $this->request;
|
return $this->request;
|
||||||
@@ -146,6 +168,10 @@ abstract class BaseForm
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return FormView
|
||||||
|
* @throws \LogicException
|
||||||
|
*/
|
||||||
public function getView()
|
public function getView()
|
||||||
{
|
{
|
||||||
if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first.");
|
if ($this->view === null) throw new \LogicException("View was not created. Please call BaseForm::createView() first.");
|
||||||
|
|||||||
Reference in New Issue
Block a user