mirror of
https://github.com/silverstripe/silverstripe-multiform
synced 2024-10-22 11:05:49 +02:00
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:
parent
4f1510ff5b
commit
01ff2cb36a
@ -75,7 +75,12 @@ abstract class MultiForm extends Form {
|
|||||||
public static $actions_exempt_from_validation = array(
|
public static $actions_exempt_from_validation = array(
|
||||||
'action_prev'
|
'action_prev'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $displayLink;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the MultiForm instance.
|
* Start the MultiForm instance.
|
||||||
*
|
*
|
||||||
@ -507,6 +512,29 @@ abstract class MultiForm extends Form {
|
|||||||
return $action;
|
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
|
* Determine the steps to show in a linear fashion, starting from the
|
||||||
* first step. We run {@link getAllStepsRecursive} passing the steps found
|
* first step. We run {@link getAllStepsRecursive} passing the steps found
|
||||||
|
@ -126,7 +126,7 @@ class MultiFormStep extends DataObject {
|
|||||||
* @return string Relative URL to this step
|
* @return string Relative URL to this step
|
||||||
*/
|
*/
|
||||||
public function Link() {
|
public function Link() {
|
||||||
return Controller::curr()->Link() . '?MultiFormSessionID=' . $this->Session()->Hash;
|
return Controller::join_links($this->form->getDisplayLink(), "?MultiFormSessionID={$this->Session()->Hash}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user