From ae302e2c17acb541d11758fdbd17e056229e05bf Mon Sep 17 00:00:00 2001 From: Jim Graham Date: Wed, 1 Dec 2021 00:45:29 -0500 Subject: [PATCH] Feature: Multi Page Form Support Changes how hasSubmission() is evaluated to allow alternate buttons to submit the form (relevant in multi-step/page forms) --- core/components/formit/src/FormIt/Request.php | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/core/components/formit/src/FormIt/Request.php b/core/components/formit/src/FormIt/Request.php index 00d1de1b..b323602a 100644 --- a/core/components/formit/src/FormIt/Request.php +++ b/core/components/formit/src/FormIt/Request.php @@ -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: + + + + + 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;