Skip to content

Commit

Permalink
Feature: Multi Page Form Support
Browse files Browse the repository at this point in the history
Changes how hasSubmission() is evaluated to allow alternate buttons to submit the form (relevant in multi-step/page forms)
  • Loading branch information
Jim Graham committed Dec 1, 2021
1 parent ea06b1c commit ae302e2
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion core/components/formit/src/FormIt/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,32 @@ public function hasSubmission()
$inPost = false;
if (!empty($_POST)) {
$inPost = true;
if (!empty($this->config['submitVar']) && empty($_POST[$this->config['submitVar']])) {
/*
Changed to provide means to allow multiple submit buttons in one form. The primary use case is multi-step/page forms,
where buttons used to navigate the form should post the current page data before moving to the specified step.
Each button of type submit should have a unique name that includes the value of the submitVar parameter, as well as
a value that differetiates the button's functionality. For example, in a chunk template the basic form navigation might be:
<button type="submit" title="Previous" name="[[!+submitVar]]_prev" value="[[!+submitValPrev]]">Previous</button>
<button type="submit" title="Next" name="[[!+submitVar]]>Next</button>
<button type="submit" title="Last" name="[[!+submitVar]]_last" value="[[!+submitValLast]]">Skip to Last Step</button>
where the value is the step index to redirect to after submission (which would be optional for the regular submit button,
which is shown here as "Next").
This change should not require users to make changes to their existing forms.
*/
if (!empty($this->config['submitVar'])) {
$keys = array_keys($_POST);
$inPost = false;
foreach ($keys as $key) {
if (strpos($key, $this->config['submitVar']) !== false) {
$inPost = true;
break;
}
}
}

}

return $inPost;
Expand Down

0 comments on commit ae302e2

Please sign in to comment.