From aa658fac3abe3873fc70231f5eb0e0c53466ce54 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 6 Aug 2015 12:06:56 +0000 Subject: [PATCH] form : allow checkbox to be multiple (in an array) or simple (in text) git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2213 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- form.php | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/form.php b/form.php index 03666c5..6fbaf64 100644 --- a/form.php +++ b/form.php @@ -276,24 +276,32 @@ class formfield $this->titles = array (""); foreach ($this->titles as $key=>$val) { - $res .= "
"; - $res .= " name, ENT_QUOTES)."][$key]'"; - $res .= " value='unset'"; + $res .= htmlspecialchars ($this->name, ENT_QUOTES)."]"; + if (count ($this->titles) > 1) + $res .= "[$key]"; + $res .= "' value='unset'"; $res .= "/>"; $res .= "name, ENT_QUOTES)."][$key]'"; - $res .= " id='$this->formName"."_"; - $res .= htmlspecialchars ($this->name, ENT_QUOTES)."_$key'"; + $res .= htmlspecialchars ($this->name, ENT_QUOTES)."]"; + if (count ($this->titles) > 1) + $res .= "[$key]"; + $res .= "' id='$this->formName"."_"; + $res .= htmlspecialchars ($this->name, ENT_QUOTES); + if (count ($this->titles) > 1) + $res .= "_$key"; + $res .= "'"; if (isset ($this->readonly) && $this->readonly !== FALSE) $res .= " disabled='disabled'"; - if (isset ($this->values[$key]) && - $this->values[$key] !== "unset") + if (count ($this->titles) === 1 && isset ($this->values) && + $this->values !== "unset") $res .= " checked='checked'"; - elseif (isset ($this->defaults[$key]) && - $this->defaults[$key] !== "") + elseif (isset ($this->values[$key]) && $this->values[$key] !== "unset") + $res .= " checked='checked'"; + elseif (isset ($this->defaults[$key]) && $this->defaults[$key] !== "") $res .= " checked='checked'"; if (isset ($this->hidden) && $this->hidden !== FALSE) $res .= " style='display:none'"; @@ -304,14 +312,14 @@ class formfield } $res .= "/>"; $res .= "$val\n"; - $res .= "
\n"; + $res .= " \n"; } if (isset ($this->errors) || isset ($this->help)) { $res .= " "; - if (isset ($this->help)) $res .= $this->help."
\n"; + if (isset ($this->help)) $res .= $this->help."
"; if (isset ($this->errors)) $res .= $this->errors[1]; $res .= "
\n"; }