Horde_Form::validate PHP Method

validate() public method

Validates the form, checking if it really has been submitted by calling isSubmitted() and if true does any onSubmit() calls for variable types in the form. The _submitted variable is then rechecked.
public validate ( Variables $vars = null, $canAutoFill = false ) : boolean
$vars Variables A Variables instance, optional since Horde 3.2.
return boolean True if the form is valid.
    function validate($vars = null, $canAutoFill = false)
    {
        if (is_null($vars)) {
            $vars = $this->_vars;
        }
        /* Get submitted status. */
        if ($this->isSubmitted() || $canAutoFill) {
            /* Form was submitted or can autofill; check for any variable
             * types' onSubmit(). */
            $this->onSubmit($vars);
            /* Recheck submitted status. */
            if (!$this->isSubmitted() && !$canAutoFill) {
                return false;
            }
        } else {
            /* Form has not been submitted; return false. */
            return false;
        }
        $message = '';
        $this->_autofilled = true;
        if ($this->_useFormToken) {
            try {
                $tokenSource = $GLOBALS['injector']->getInstance('Horde_Token');
                $passedToken = $vars->get($this->_name . '_formToken');
                if (!empty($passedToken) && !$tokenSource->verify($passedToken)) {
                    $this->_errors['_formToken'] = Horde_Form_Translation::t("This form has already been processed.");
                }
            } catch (Horde_Exception $e) {
            }
            if (!$GLOBALS['session']->get('horde', 'form_secrets/' . $passedToken)) {
                $this->_errors['_formSecret'] = Horde_Form_Translation::t("Required secret is invalid - potentially malicious request.");
            }
        }
        foreach ($this->getVariables() as $var) {
            $this->_autofilled = $var->_autofilled && $this->_autofilled;
            if (!$var->validate($vars, $message)) {
                $this->_errors[$var->getVarName()] = $message;
            }
        }
        if ($this->_autofilled) {
            unset($this->_errors['_formToken']);
        }
        foreach ($this->_hiddenVariables as $var) {
            if (!$var->validate($vars, $message)) {
                $this->_errors[$var->getVarName()] = $message;
            }
        }
        return $this->isValid();
    }

Usage Example

示例#1
0
 public function validate(&$vars)
 {
     if (!Whups::hasPermission($this->_queue, 'queue', Horde_Perms::DELETE)) {
         $this->setError('yesno', _("Permission Denied."));
     }
     return parent::validate($vars);
 }
All Usage Examples Of Horde_Form::validate