diff --git a/core/lib/Thelia/Form/BaseForm.php b/core/lib/Thelia/Form/BaseForm.php index a3220fa8b..40753b256 100755 --- a/core/lib/Thelia/Form/BaseForm.php +++ b/core/lib/Thelia/Form/BaseForm.php @@ -70,9 +70,35 @@ abstract class BaseForm { $this->buildForm(); + // If not already set, define the success_url field + if (! $this->formBuilder->has('success_url')) { + $this->formBuilder->add("success_url", "text") + } + $this->form = $this->formBuilder->getForm(); } + /** + * Returns the absolute URL to redirect the user to if the form is successfully processed. + * + * @param string $default the default URL. If not given, the configured base URL is used. + * + * @return string an absolute URL + */ + public function getSuccessUrl($default = null) { + + $successUrl = $this->form->get('success_url')->getData(); + + if (empty($successUrl)) { + + if ($default === null) $default = ConfigQuery::read('base_url', '/'); + + $successUrl = $default; + } + + return URL::absoluteUrl($successUrl); + } + public function createView() { $this->view = $this->form->createView(); } @@ -96,7 +122,7 @@ abstract class BaseForm { * in this function you add all the fields you need for your Form. * Form this you have to call add method on $this->formBuilder attribute : * - * $this->form->add("name", "text") + * $this->formBuilder->add("name", "text") * ->add("email", "email", array( * "attr" => array( * "class" => "field"