From a04807bf0be7a836a06257481708e49c80256720 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 6 Aug 2015 14:28:55 +0000 Subject: [PATCH] form : add support to save the values and errors to redisplay the form in without code line ! Just add "$form->saveValuesErrors ($values, $errors);" in post routing to save the data, and in get they will be automatically re-displayed git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2216 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- form.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/form.php b/form.php index 3c48458..a694f61 100644 --- a/form.php +++ b/form.php @@ -126,6 +126,17 @@ class form die ("FORM/VERIFY : UNUSED and deprecated\n"); } + /** Save the values and errors to be displayed in the next page if the session + is available */ + public function saveValuesErrors ($values, $errors) + { + if (isset ($_SESSION)) + { + $_SESSION["domframework"]["form"]["values"] = $values; + $_SESSION["domframework"]["form"]["errors"] = $errors; + } + } + /** Return the fields in HTML code. If $values is provided, use it in place of default values. In case of select boxes, $values are the selected elements @@ -147,6 +158,13 @@ class form $res .= " id='$this->formName'"; $res .= " class='form-horizontal'>\n"; $group = ""; + if (isset ($_SESSION["domframework"]["form"]["values"])) + { + $values = $_SESSION["domframework"]["form"]["values"]; + $errors = $_SESSION["domframework"]["form"]["errors"]; + unset ($_SESSION["domframework"]["form"]["values"]); + unset ($_SESSION["domframework"]["form"]["errors"]); + } foreach ($this->fields as $field) { $field->formName = $this->formName;