From 01ff2cb36a2677053504389ab4c3d39cc2529f81 Mon Sep 17 00:00:00 2001 From: ajshort Date: Mon, 19 Dec 2011 21:38:25 +1100 Subject: [PATCH] ENHANCEMENT: Added a method to set the link where the form is displayed, allowing multiforms to run inside controller actions. --- code/MultiForm.php | 30 +++++++++++++++++++++++++++++- code/MultiFormStep.php | 2 +- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/code/MultiForm.php b/code/MultiForm.php index df30cb3..5af06aa 100644 --- a/code/MultiForm.php +++ b/code/MultiForm.php @@ -75,7 +75,12 @@ abstract class MultiForm extends Form { public static $actions_exempt_from_validation = array( 'action_prev' ); - + + /** + * @var string + */ + protected $displayLink; + /** * Start the MultiForm instance. * @@ -507,6 +512,29 @@ abstract class MultiForm extends Form { return $action; } + /** + * Returns the link to the page where the form is displayed. The user is + * redirected to this link with a session param after each step is + * submitted. + * + * @return string + */ + public function getDisplayLink() { + return $this->displayLink ? $this->displayLink : Controller::curr()->Link(); + } + + /** + * Set the link to the page on which the form is displayed. + * + * The link defaults to the controllers current link. However if the form + * is displayed inside an action the display link must be explicitly set. + * + * @param string $link + */ + public function setDisplayLink($link) { + $this->displayLink = $link; + } + /** * Determine the steps to show in a linear fashion, starting from the * first step. We run {@link getAllStepsRecursive} passing the steps found diff --git a/code/MultiFormStep.php b/code/MultiFormStep.php index c05d71c..7816459 100644 --- a/code/MultiFormStep.php +++ b/code/MultiFormStep.php @@ -126,7 +126,7 @@ class MultiFormStep extends DataObject { * @return string Relative URL to this step */ public function Link() { - return Controller::curr()->Link() . '?MultiFormSessionID=' . $this->Session()->Hash; + return Controller::join_links($this->form->getDisplayLink(), "?MultiFormSessionID={$this->Session()->Hash}"); } /**