form : Add redirectIfError method to simplify the code in index files
$form = new \form ();
$values = $form->values ();
$errors = $spaceObj->verify ($values);
$form->redirectIfError ($values, $errors, $route, "/admin/space/");
$spaceuuid = $spaceObj->spaceCreateConceal ($values["spacename"]);
$route->redirect ("/admin/space/");
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4174 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
25
form.php
25
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
|
||||
|
||||
Reference in New Issue
Block a user