mirror of
https://github.com/silverstripe/silverstripe-multiform
synced 2024-10-22 11:05:49 +02:00
ENHANCEMENT Removed hack of specific action to bypass validation and allow specifying actions to be exempt through a public static variable
This commit is contained in:
parent
f72761356b
commit
9f8d2e1da8
@ -56,6 +56,20 @@ abstract class MultiForm extends Form {
|
|||||||
'SecurityID'
|
'SecurityID'
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Any of the actions defined in this variable are exempt from
|
||||||
|
* being validated.
|
||||||
|
*
|
||||||
|
* This is most useful for the "Back" (action_prev) action, as
|
||||||
|
* you typically don't validate the form when the user is going
|
||||||
|
* back a step.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
|
*/
|
||||||
|
public static $actions_exempt_from_validation = array(
|
||||||
|
'action_prev'
|
||||||
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start the MultiForm instance.
|
* Start the MultiForm instance.
|
||||||
*
|
*
|
||||||
@ -84,9 +98,21 @@ abstract class MultiForm extends Form {
|
|||||||
$actions = $this->actionsFor($currentStep);
|
$actions = $this->actionsFor($currentStep);
|
||||||
|
|
||||||
// Set up validation (if necessary)
|
// Set up validation (if necessary)
|
||||||
// @todo find a better way instead of hardcoding a check for action_prev in order to prevent validation when hitting the back button
|
|
||||||
$validator = null;
|
$validator = null;
|
||||||
if(empty($_REQUEST['action_prev'])) {
|
$applyValidation = true;
|
||||||
|
|
||||||
|
// Check if the $_REQUEST action that user clicked is an exempt one
|
||||||
|
if(self::$actions_exempt_from_validation) {
|
||||||
|
foreach(self::$actions_exempt_from_validation as $exemptAction) {
|
||||||
|
if(!empty($_REQUEST[$exemptAction])) {
|
||||||
|
$applyValidation = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply validation if the current step requires validation (is not exempt)
|
||||||
|
if($applyValidation) {
|
||||||
if($this->getCurrentStep()->getValidator()) {
|
if($this->getCurrentStep()->getValidator()) {
|
||||||
$validator = $this->getCurrentStep()->getValidator();
|
$validator = $this->getCurrentStep()->getValidator();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user