ENHANCEMENT: Added a method to set the link where the form is displayed, allowing multiforms to run inside controller actions.

This commit is contained in:
ajshort 2011-12-19 21:38:25 +11:00
parent 4f1510ff5b
commit 01ff2cb36a
2 changed files with 30 additions and 2 deletions

View File

@ -76,6 +76,11 @@ abstract class MultiForm extends Form {
'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

View File

@ -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}");
}
/**