diff --git a/form.php b/form.php index dab28e9..132452b 100644 --- a/form.php +++ b/form.php @@ -337,6 +337,31 @@ class form return $errors; } + /** If there is at least one error reported in $errors, save the old values + * and the errors in the session, and redirect to the provided url. + * If there is no error, do nothing + * @param array $values The values of the fields filled by the user + * @param array $errors The errors detected by a verify + * @param object $route the route object + * @param string $url The URL to redirect + * + * Example : + $form = new \form (); + $form->logging (array ('\apps\general\controllers\logging', 'log'), + $authHTML["email"]); + $values = $form->values (); + $errors = $spaceObj->verify ($values); + $form->redirectIfError ($values, $errors, $route, "/admin/space/"); + $spaceuuid = $spaceObj->spaceCreateConceal ($values["spacename"]); + $route->redirect ("/admin/space/"); + */ + public function redirectIfError ($values, $errors, $route, $url) + { + $this->saveValuesErrors ($values, $errors); + if (count ($errors)) $route->redirect ($url); + $form->saveValuesErrorsReset (); + } + /** Save the values and errors to be displayed in the next page if the session * is available * Need the session to work