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:
Sean Harvey 2008-12-17 11:08:46 +00:00
parent f72761356b
commit 9f8d2e1da8

View File

@ -56,6 +56,20 @@ abstract class MultiForm extends Form {
'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.
*
@ -84,9 +98,21 @@ abstract class MultiForm extends Form {
$actions = $this->actionsFor($currentStep);
// 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;
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()) {
$validator = $this->getCurrentStep()->getValidator();
}