-
Notifications
You must be signed in to change notification settings - Fork 11
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: Support Multi-Step Paged Forms #18
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,7 +147,7 @@ public function run(array $properties = []) | |
$hooks[] = 'FormaliciousHookHandleForm'; | ||
} | ||
|
||
if ($currentStep >= $totalSteps) { | ||
if ($currentStep >= $totalSteps && isset($_POST[$parameters['submitVar']])) { | ||
if (!in_array('FormaliciousHookRemoveForm', $hooks, true)) { | ||
$hooks[] = 'FormaliciousHookRemoveForm'; | ||
} | ||
|
@@ -198,8 +198,30 @@ public function run(array $properties = []) | |
} else { | ||
$hooks[] = 'redirect'; | ||
|
||
/* | ||
Set up redirect in a way that allows variable/dynamic destination, based on | ||
value stored in the submit input/button. This way, form data on the step that is | ||
being navigated away from will always be posted/saved. Navigation and pagination | ||
should then be done via submit inputs/buttons instead of <a> tags. | ||
|
||
A related change to FormIt's Request class is necessary for this additional functionality. | ||
*/ | ||
|
||
# Default redirect destination | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smg6511 Can you make this a single line PHP comment like this? |
||
$destination = $currentStep + 1; | ||
|
||
# Check for alternate destination request | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smg6511 And like this: |
||
if ($_POST) { | ||
foreach ($_POST as $k => $v) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smg6511 Could you make the variable names minimum of three characters long?
|
||
if (strpos($k, $parameters['submitVar']) !== false) { | ||
$destination = is_numeric($v) ? $v : $destination ; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
$parameters['redirectTo'] = $this->getStepUrl([ | ||
$this->getProperty('stepParam') => $currentStep + 1 | ||
$this->getProperty('stepParam') => (int)$destination | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smg6511 Please add a whitespace after So: |
||
], 'full'); | ||
|
||
if (empty($placeholders['submitTitle'])) { | ||
|
@@ -226,21 +248,23 @@ public function run(array $properties = []) | |
$parameters['formaliciousTplNavigationItem'] = $this->getProperty('tplNavigationItem'); | ||
$parameters['formaliciousTplNavigationWrapper'] = $this->getProperty('tplNavigationWrapper'); | ||
|
||
if ($currentStep <= 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you think we need to remove Can you please describe this or return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may be not accounting for a particular scenario, but why would you show a previous URL if you're on the first step? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with you. But if we delete this, we should change major version number I think. Because this broke backward compatibility. But maybe I'm wrong. I will ask somebody There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, let me know. FYI, I verified that this change we're debating does not affect the functionality I'm introducing, so it can be reverted back if needed. If I remember, I made that change because the original line in the code caught my eye and didn't make sense to me. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smg6511 First of all, thank you for putting in the work!
Also could you add a section in the readme describing what you added and how that can be implemented? This will make it easier for other users to find out that it is possible and how they can achieve this. |
||
$placeholders['prevUrl'] = $this->getStepUrl(); | ||
} else { | ||
if ($currentStep > 1) { | ||
$placeholders['prevUrl'] = $this->getStepUrl([ | ||
$this->getProperty('stepParam') => $currentStep - 1 | ||
]); | ||
$placeholders['submitValPrev'] = $currentStep - 1; | ||
} | ||
|
||
if ($totalSteps === 1) { | ||
$placeholders['currentUrl'] = $this->getStepUrl(); | ||
} else { | ||
$placeholders['currentUrl'] = $this->getStepUrl([ | ||
$this->getProperty('stepParam') => $currentStep | ||
]); | ||
} | ||
$placeholders['submitValLast'] = $totalSteps; | ||
|
||
# Suggest renaming this placeholder, as it makes its purpose more immediately clear | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smg6511 Can you format this like: |
||
$placeholders['formAction'] = $totalSteps === 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @smg6511 Can you move the
|
||
? $this->getStepUrl() | ||
: $this->getStepUrl([$this->getProperty('stepParam') => $currentStep]) | ||
; | ||
|
||
# Set orignal for backward compatibility | ||
$placeholders['currentUrl'] = $placeholders['formAction']; | ||
|
||
return $this->getChunk($this->getProperty('tplForm'), array_merge($placeholders, $parameters, [ | ||
'FormItParameters' => $this->parseParameters($parameters), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@smg6511 Can you please format this multi line comment like this?