form : supports multiple forms on the same page
git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4177 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
95
form.php
95
form.php
@@ -51,6 +51,62 @@ class form
|
||||
$this->formName = $formName;
|
||||
}
|
||||
|
||||
// The setters of the properties
|
||||
// {{{
|
||||
/** Set the debug level
|
||||
* @param integer $val The debug value
|
||||
*/
|
||||
public function debug ($val)
|
||||
{
|
||||
$this->debug = $val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** Set the csrf enable
|
||||
* @param integer $val The csrf check
|
||||
*/
|
||||
public function csrf ($val)
|
||||
{
|
||||
$this->csrf = !! $val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** Set the csrf token name
|
||||
* @param integer $val The csrf token name
|
||||
*/
|
||||
public function csrfField ($val)
|
||||
{
|
||||
$this->csrfField = $val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** Set the titlewidth
|
||||
* @param integer $val The titlewidth
|
||||
*/
|
||||
public function titlewidth ($val)
|
||||
{
|
||||
$this->titlewidth = $val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** Set the fieldwidth
|
||||
* @param integer $val The fieldwidth
|
||||
*/
|
||||
public function fieldwidth ($val)
|
||||
{
|
||||
$this->fieldwidth = $val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** Set the formClass
|
||||
* @param integer $val The formClass
|
||||
*/
|
||||
public function formClass ($val)
|
||||
{
|
||||
$this->formClass = $val;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** Set logging class an method
|
||||
* @param callable $loggingCallable The callable function. This method will
|
||||
* receive two params : the LOG level (LOG_ERROR...) and the message
|
||||
@@ -61,6 +117,7 @@ class form
|
||||
$this->loggingCallable = $loggingCallable;
|
||||
$this->loggingBasemsg = $loggingBasemsg;
|
||||
}
|
||||
// }}}
|
||||
|
||||
/** The private method to log if the $this->loggingCallable is defined
|
||||
*/
|
||||
@@ -157,9 +214,10 @@ class form
|
||||
// Remove the field CSRF : can not be used outside the form
|
||||
unset ($values[$this->csrfField]);
|
||||
}
|
||||
if (isset ($_SESSION["domframework"]["form"]["fields"]))
|
||||
if (isset ($_SESSION["domframework"]["form"][$this->formName]["fields"]))
|
||||
{
|
||||
foreach ($_SESSION["domframework"]["form"]["fields"] as $field)
|
||||
foreach ($_SESSION["domframework"]["form"][$this->formName]["fields"] as
|
||||
$field)
|
||||
{
|
||||
if ($field->type === "hidden" ||
|
||||
($field->readonly !== null && $field->readonly !== false))
|
||||
@@ -194,7 +252,8 @@ class form
|
||||
throw new Exception ("Can't display a form without defined field", 500);
|
||||
}
|
||||
if (isset ($_SESSION))
|
||||
$_SESSION["domframework"]["form"]["fields"] = $this->fields;
|
||||
$_SESSION["domframework"]["form"][$this->formName]["fields"] =
|
||||
$this->fields;
|
||||
$this->method = strtolower ($method);
|
||||
$res = "";
|
||||
$res = "<form action='#' method='$method'";
|
||||
@@ -202,12 +261,12 @@ class form
|
||||
$res .= " id='$this->formName'";
|
||||
$res .= " class='".$this->formClass."'>\n";
|
||||
$group = "";
|
||||
if (isset ($_SESSION["domframework"]["form"]["values"]))
|
||||
if (isset ($_SESSION["domframework"]["form"][$this->formName]["values"]))
|
||||
{
|
||||
$values = $_SESSION["domframework"]["form"]["values"];
|
||||
$errors = $_SESSION["domframework"]["form"]["errors"];
|
||||
unset ($_SESSION["domframework"]["form"]["values"]);
|
||||
unset ($_SESSION["domframework"]["form"]["errors"]);
|
||||
$values = $_SESSION["domframework"]["form"][$this->formName]["values"];
|
||||
$errors = $_SESSION["domframework"]["form"][$this->formName]["errors"];
|
||||
unset ($_SESSION["domframework"]["form"][$this->formName]["values"]);
|
||||
unset ($_SESSION["domframework"]["form"][$this->formName]["errors"]);
|
||||
}
|
||||
foreach ($this->fields as $field)
|
||||
{
|
||||
@@ -375,8 +434,8 @@ class form
|
||||
{
|
||||
if (isset ($_SESSION))
|
||||
{
|
||||
$_SESSION["domframework"]["form"]["values"] = $values;
|
||||
$_SESSION["domframework"]["form"]["errors"] = $errors;
|
||||
$_SESSION["domframework"]["form"][$this->formName]["values"] = $values;
|
||||
$_SESSION["domframework"]["form"][$this->formName]["errors"] = $errors;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,8 +444,8 @@ class form
|
||||
*/
|
||||
public function saveValuesErrorsReset ()
|
||||
{
|
||||
unset ($_SESSION["domframework"]["form"]["values"]);
|
||||
unset ($_SESSION["domframework"]["form"]["errors"]);
|
||||
unset ($_SESSION["domframework"]["form"][$this->formName]["values"]);
|
||||
unset ($_SESSION["domframework"]["form"][$this->formName]["errors"]);
|
||||
}
|
||||
|
||||
/** Get the stored values if there is one. If there is no stored values,
|
||||
@@ -396,10 +455,10 @@ class form
|
||||
*/
|
||||
public function getOldValues ($values)
|
||||
{
|
||||
if (isset ($_SESSION["domframework"]["form"]["values"]))
|
||||
if (isset ($_SESSION["domframework"]["form"][$this->formName]["values"]))
|
||||
{
|
||||
$values = $_SESSION["domframework"]["form"]["values"];
|
||||
unset ($_SESSION["domframework"]["form"]["values"]);
|
||||
$values = $_SESSION["domframework"]["form"][$this->formName]["values"];
|
||||
unset ($_SESSION["domframework"]["form"][$this->formName]["values"]);
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
@@ -411,10 +470,10 @@ class form
|
||||
*/
|
||||
public function getOldErrors ($errors)
|
||||
{
|
||||
if (isset ($_SESSION["domframework"]["form"]["errors"]))
|
||||
if (isset ($_SESSION["domframework"]["form"][$this->formName]["errors"]))
|
||||
{
|
||||
$errors = $_SESSION["domframework"]["form"]["errors"];
|
||||
unset ($_SESSION["domframework"]["form"]["errors"]);
|
||||
$errors = $_SESSION["domframework"]["form"][$this->formName]["errors"];
|
||||
unset ($_SESSION["domframework"]["form"][$this->formName]["errors"]);
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user