Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Multi Page Form Support #259

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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