diff --git a/library/Icinga/Web/Form.php b/library/Icinga/Web/Form.php index 8d2e4f333..54d89e271 100644 --- a/library/Icinga/Web/Form.php +++ b/library/Icinga/Web/Form.php @@ -190,6 +190,30 @@ class Form extends Zend_Form return array(); } + /** + * Perform actions after this form was submitted using a valid request + * + * Intended to be implemented by concrete form classes. + * + * @param Request $request The valid request used to process this form + */ + public function onSuccess(Request $request) + { + + } + + /** + * Perform actions after this form was submitted using an invalid request + * + * Intended to be implemented by concrete form classes. + * + * @param Request $request The invalid request supposed to process this form + */ + public function onFailure(Request $request) + { + + } + /** * Add a submit button to this form * @@ -292,6 +316,37 @@ class Form extends Zend_Form return parent::setDefaults($defaults); } + /** + * Process the given request using this form + * + * @param Request $request The request to be processed + * + * @return null|bool True in case the request was handled and valid, + * false if invalid and null if it was not handled + */ + public function handleRequest(Request $request) + { + if (strtolower($request->getMethod()) === $this->getMethod()) { + $formData = $request->{'get' . $request->isPost() ? 'Post' : 'Query'}(); + if ($this->wasSent($formData)) { + $this->populate($formData); // Necessary to get isSubmitted() to work + if ($this->isSubmitted()) { + if ($this->isValid($formData)) { + $this->onSuccess($request); + return true; + } else { + $this->onFailure($request); + } + } else { + // The form can't be processed but we want to show validation errors though + $this->isValidPartial($formData); + } + + return false; + } + } + } + /** * Return whether the submit button of this form was pressed *