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
This commit is contained in:
2015-08-06 12:06:56 +00:00
parent 0a5d7edfad
commit aa658fac3a

View File

@@ -276,24 +276,32 @@ class formfield
$this->titles = array (""); $this->titles = array ("");
foreach ($this->titles as $key=>$val) foreach ($this->titles as $key=>$val)
{ {
$res .= "<div class='checkbox'>"; $res .= " <div class='checkbox'>\n";
$res .= " <input type='hidden'"; $res .= " <input type='hidden'";
$res .= " name='$this->formName"."["; $res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."][$key]'"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."]";
$res .= " value='unset'"; if (count ($this->titles) > 1)
$res .= "[$key]";
$res .= "' value='unset'";
$res .= "/>"; $res .= "/>";
$res .= "<input type='checkbox'"; $res .= "<input type='checkbox'";
$res .= " name='$this->formName"."["; $res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."][$key]'"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."]";
$res .= " id='$this->formName"."_"; if (count ($this->titles) > 1)
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_$key'"; $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) if (isset ($this->readonly) && $this->readonly !== FALSE)
$res .= " disabled='disabled'"; $res .= " disabled='disabled'";
if (isset ($this->values[$key]) && if (count ($this->titles) === 1 && isset ($this->values) &&
$this->values[$key] !== "unset") $this->values !== "unset")
$res .= " checked='checked'"; $res .= " checked='checked'";
elseif (isset ($this->defaults[$key]) && elseif (isset ($this->values[$key]) && $this->values[$key] !== "unset")
$this->defaults[$key] !== "") $res .= " checked='checked'";
elseif (isset ($this->defaults[$key]) && $this->defaults[$key] !== "")
$res .= " checked='checked'"; $res .= " checked='checked'";
if (isset ($this->hidden) && $this->hidden !== FALSE) if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'"; $res .= " style='display:none'";
@@ -304,14 +312,14 @@ class formfield
} }
$res .= "/>"; $res .= "/>";
$res .= "$val\n"; $res .= "$val\n";
$res .= "</div>\n"; $res .= " </div>\n";
} }
if (isset ($this->errors) || isset ($this->help)) if (isset ($this->errors) || isset ($this->help))
{ {
$res .= " <span class='help-block' id='$this->formName"."_"; $res .= " <span class='help-block' id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>";
if (isset ($this->help)) $res .= $this->help."<br/>\n"; if (isset ($this->help)) $res .= $this->help."<br/>";
if (isset ($this->errors)) $res .= $this->errors[1]; if (isset ($this->errors)) $res .= $this->errors[1];
$res .= "</span>\n"; $res .= "</span>\n";
} }