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
This commit is contained in:
2015-08-06 14:28:55 +00:00
parent 52b0da9bc8
commit a04807bf0b

View File

@@ -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;