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:
18
form.php
18
form.php
@@ -126,6 +126,17 @@ class form
|
|||||||
die ("FORM/VERIFY : UNUSED and deprecated\n");
|
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
|
/** 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
|
of default values. In case of select boxes, $values are the selected
|
||||||
elements
|
elements
|
||||||
@@ -147,6 +158,13 @@ class form
|
|||||||
$res .= " id='$this->formName'";
|
$res .= " id='$this->formName'";
|
||||||
$res .= " class='form-horizontal'>\n";
|
$res .= " class='form-horizontal'>\n";
|
||||||
$group = "";
|
$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)
|
foreach ($this->fields as $field)
|
||||||
{
|
{
|
||||||
$field->formName = $this->formName;
|
$field->formName = $this->formName;
|
||||||
|
|||||||
Reference in New Issue
Block a user