SilverStripe\MultiForm\Forms\MultiForm
MultiForm manages the loading of single form steps, and acts as a state machine that connects to a {@link MultiFormSession} object as a persistence layer.
CAUTION: If you're using controller permission control,
you have to allow the following methods:
<code>
private static $allowed_actions = ['next','prev'];
</code>
Synopsis
class MultiForm
extends Form
{
- // members
- protected MultiFormSession $session;
- protected $currentSessionHash;
- private static $start_step;
- private static array $casting = ;
- private static string $get_var = 'MultiFormSessionID';
- private static array $ignored_fields = ;
- private static array $actions_exempt_from_validation = ;
- protected $displayLink;
- protected boolean $currentStepHasBeenFound = false;
- // methods
- public void __construct()
- public Controller getController()
- public string getGetVar()
- public MultiFormStep getCurrentStep()
- protected boolean setCurrentStep()
- public MultiFormSession getMultiFormSession()
- protected void setSession()
- public void setCurrentSessionHash()
- public MultiFormSession|boolean getCurrentSession()
- public DataList|boolean getSavedSteps()
- public DataObject getSavedStepByClass()
- public FieldList actionsFor()
- public bool finish()
- public bool next()
- public bool|HTTPResponse prev()
- protected void save()
- public string FormAction()
- public string getDisplayLink()
- public void setDisplayLink()
- public ArrayList getAllStepsLinear()
- protected DataList getAllStepsRecursive()
- public int getCompletedStepCount()
- public int getTotalStepCount()
- public float getCompletedPercent()
Hierarchy
Extends
- SilverStripe\Forms\Form
Tasks
Line | Task |
---|---|
299+ | Fix the fact you can continually refresh and create new records if MultiFormSessionID isn't set. |
299+ | Not sure if we should bake the session stuff directly into MultiForm. Perhaps it would be best dealt with on a separate class? |
698+ | Not sure if it's entirely appropriate to check if Data is set as a way to determine a step is "completed". |
Members
private
- $actions_exempt_from_validation
—
array
Any of the actions defined in this variable are exempt from being validated. - $casting
—
array
Set the casting for these fields. - $get_var — string
- $ignored_fields
—
array
These fields are ignored when saving the raw form data into session. - $start_step
—
string
Defines which subclass of {@link MultiFormStep} should be the first step in the multi-step process.
protected
- $currentSessionHash
—
string
The current encrypted MultiFormSession identification. - $currentStepHasBeenFound
—
boolean
Flag which is being used in getAllStepsRecursive() to allow adding the completed flag on the steps - $displayLink — string
- $session
—
SilverStripe\MultiForm\Models\MultiFormSession
A session object stored in the database, to identify and store data for this MultiForm instance.
Methods
protected
- getAllStepsRecursive() — Recursively run through steps using the getNextStep() method on each step to determine what the next step is, gathering each step along the way.
- save() — Save the raw data given back from the form into session.
- setCurrentStep() — Set the step passed in as the current step.
- setSession() — Set up the session.
public
- __construct() — Start the MultiForm instance.
- FormAction() — Add the MultiFormSessionID variable to the URL on form submission.
- actionsFor() — Build a FieldList of the FormAction fields for the given step.
- finish() — This method saves the data on the final step, after submitting.
- getAllStepsLinear() — Determine the steps to show in a linear fashion, starting from the first step. We run {@link getAllStepsRecursive} passing the steps found by reference to get a listing of the steps.
- getCompletedPercent() — Percentage of steps completed (excluding currently started step)
- getCompletedStepCount() — Number of steps already completed (excluding currently started step).
- getController() — Accessor method to $this->controller.
- getCurrentSession() — Return the currently used {@link MultiFormSession}
- getCurrentStep() — Get the current step.
- getDisplayLink() — 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.
- getGetVar() — Returns the get_var to the template engine
- getMultiFormSession() — Accessor method to $this->session.
- getSavedStepByClass() — Get a step which was previously saved to the database in the current session.
- getSavedSteps() — Get all steps saved in the database for the currently active session, in the order they were saved, oldest to newest (automatically ordered by ID).
- getTotalStepCount() — Total number of steps in the shortest path (only counting straight path without any branching) The way we determine this is to check if each step has a next_step string variable set. If it's anything else (like an array, for defining multiple branches) then it gets counted as a single step.
- next() — Determine what to do when the next action is called.
- prev() — Determine what to do when the previous action is called.
- setCurrentSessionHash() — Set the currently used encrypted hash to identify the MultiFormSession.
- setDisplayLink() — Set the link to the page on which the form is displayed.