BUG form : allow the values and the errors to be displayed

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2187 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-06-08 09:57:42 +00:00
parent 440eba1415
commit 126bd24022

View File

@@ -154,6 +154,12 @@ class form
} }
$res .=" "; $res .=" ";
if (isset ($values[$field->name]) &&
$values[$field->name] !== "unset")
$field->values = $values[$field->name];
if (isset ($errors[$field->name]) &&
$errors[$field->name] !== "unset")
$field->errors = $errors[$field->name];
$res .= $field->display (); $res .= $field->display ();
} }
@@ -235,8 +241,8 @@ class formfield
// No $this->multiple, $this->rows $this->cols // No $this->multiple, $this->rows $this->cols
$res = ""; $res = "";
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " has-".$errors[$this->name][0]; $res .= " has-".$this->errors[0];
$res .= "'>\n"; $res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='". $res .= " <label class='col-sm-2 control-label' for='".
$this->formName."_"; $this->formName."_";
@@ -267,8 +273,8 @@ class formfield
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_$key'"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."_$key'";
if (isset ($this->readonly) && $this->readonly !== FALSE) if (isset ($this->readonly) && $this->readonly !== FALSE)
$res .= " disabled='disabled'"; $res .= " disabled='disabled'";
if (isset ($values[$this->name][$key]) && if (isset ($this->values[$key]) &&
$values[$this->name][$key] !== "unset") $this->values[$key] !== "unset")
$res .= " checked='checked'"; $res .= " checked='checked'";
elseif (isset ($this->defaults[$key]) && elseif (isset ($this->defaults[$key]) &&
$this->defaults[$key] !== "") $this->defaults[$key] !== "")
@@ -280,8 +286,8 @@ class formfield
$res .= "$val\n"; $res .= "$val\n";
} }
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " <span class='help-block'>".$errors[$this->name][1]. $res .= " <span class='help-block'>".$this->errors[1].
"</span>\n"; "</span>\n";
$res .= " </div>\n"; // End controls $res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group $res .= " </div>\n"; // End form-group
@@ -299,8 +305,8 @@ class formfield
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$res .= " id='$this->formName"."_"; $res .= " id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."'"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."'";
if (isset ($values[$this->name])) if (isset ($this->values))
$res .= " value='".htmlspecialchars ($values[$this->name])."'"; $res .= " value='".htmlspecialchars ($this->values)."'";
else else
$res .= " value='".htmlspecialchars ($this->defaults)."'"; $res .= " value='".htmlspecialchars ($this->defaults)."'";
$res .= "/>\n"; $res .= "/>\n";
@@ -313,8 +319,8 @@ class formfield
$res = ""; $res = "";
// No $this->multiple, $this->rows $this->cols // No $this->multiple, $this->rows $this->cols
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " has-".$errors[$this->name][0]; $res .= " has-".$this->errors[0];
$res .= "'>\n"; $res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='". $res .= " <label class='col-sm-2 control-label' for='".
$this->formName."_"; $this->formName."_";
@@ -334,8 +340,8 @@ class formfield
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$res .= " id='$this->formName"."_"; $res .= " id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."'"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."'";
if (isset ($values[$this->name])) if (isset ($this->values))
$res .= " value='".htmlspecialchars ($values[$this->name], $res .= " value='".htmlspecialchars ($this->values,
ENT_QUOTES)."'"; ENT_QUOTES)."'";
else else
$res .= " value='".htmlspecialchars ($this->defaults, ENT_QUOTES). $res .= " value='".htmlspecialchars ($this->defaults, ENT_QUOTES).
@@ -346,8 +352,8 @@ class formfield
if (isset ($this->hidden) && $this->hidden !== FALSE) if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'"; $res .= " style='display:none'";
$res .= "/>\n"; $res .= "/>\n";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " <span class='help-block'>".$errors[$this->name][1]. $res .= " <span class='help-block'>".$this->errors[1].
"</span>\n"; "</span>\n";
$res .= " </div>\n"; // End controls $res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group $res .= " </div>\n"; // End form-group
@@ -360,8 +366,8 @@ class formfield
$res = ""; $res = "";
// No $this->multiple, $this->rows $this->cols // No $this->multiple, $this->rows $this->cols
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " has-".$errors[$this->name][0]; $res .= " has-".$this->errors[0];
$res .= "'>\n"; $res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='". $res .= " <label class='col-sm-2 control-label' for='".
$this->formName."_"; $this->formName."_";
@@ -394,8 +400,8 @@ class formfield
$res .= " value='".htmlspecialchars ($val, ENT_QUOTES)."'"; $res .= " value='".htmlspecialchars ($val, ENT_QUOTES)."'";
if (isset ($this->readonly) && $this->readonly !== FALSE) if (isset ($this->readonly) && $this->readonly !== FALSE)
$res .= " readonly='readonly'"; $res .= " readonly='readonly'";
if (isset ($values[$this->name]) && if (isset ($this->values) &&
$values[$this->name] === $val) $this->values === $val)
$res .= " checked='checked'"; $res .= " checked='checked'";
elseif (isset ($this->defaults[0]) && elseif (isset ($this->defaults[0]) &&
$this->defaults[0] === $val) $this->defaults[0] === $val)
@@ -408,8 +414,8 @@ class formfield
$res .= "</label>\n"; // End label radio $res .= "</label>\n"; // End label radio
} }
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " <span class='help-block'>".$errors[$this->name][1]. $res .= " <span class='help-block'>".$this->errors[1].
"</span>\n"; "</span>\n";
$res .= " </div>\n"; // End controls $res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group $res .= " </div>\n"; // End form-group
@@ -422,8 +428,8 @@ class formfield
$res = ""; $res = "";
// $values->$this, $this->cols // $values->$this, $this->cols
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " has-".$errors[$this->name][0]; $res .= " has-".$this->errors[0];
$res .= "'>\n"; $res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='". $res .= " <label class='col-sm-2 control-label' for='".
$this->formName."_"; $this->formName."_";
@@ -484,13 +490,13 @@ class formfield
{ {
$res .= " <option value='"; $res .= " <option value='";
$res .= htmlspecialchars ($key, ENT_QUOTES)."'"; $res .= htmlspecialchars ($key, ENT_QUOTES)."'";
if (isset ($values[$this->name]) && if (isset ($this->values) &&
is_string ($values[$this->name]) && is_string ($this->values) &&
$values[$this->name] == $key) $this->values == $key)
$res .= " selected='selected'"; $res .= " selected='selected'";
elseif (isset ($values[$this->name]) && elseif (isset ($this->values) &&
is_array ($values[$this->name]) && is_array ($this->values) &&
in_array ($key, $values[$this->name])) in_array ($key, $this->values))
$res .= " selected='selected'"; $res .= " selected='selected'";
$res .= ">"; $res .= ">";
$res .= htmlspecialchars ($val); $res .= htmlspecialchars ($val);
@@ -498,8 +504,8 @@ class formfield
} }
$res .= " </select>\n"; $res .= " </select>\n";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " <span class='help-block'>".$errors[$this->name][1]. $res .= " <span class='help-block'>".$this->errors[1].
"</span>\n"; "</span>\n";
} }
else else
@@ -547,8 +553,8 @@ class formfield
$res = ""; $res = "";
// No $this->multiple, $this->titles // No $this->multiple, $this->titles
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " has-".$errors[$this->name][0]; $res .= " has-".$this->errors[0];
$res .= "'>\n"; $res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='". $res .= " <label class='col-sm-2 control-label' for='".
$this->formName."_"; $this->formName."_";
@@ -580,13 +586,13 @@ class formfield
$this->rows = 4; $this->rows = 4;
$res .= " rows='".$this->rows."'"; $res .= " rows='".$this->rows."'";
$res .= ">"; $res .= ">";
if (isset ($values[$this->name])) if (isset ($this->values))
$res .= htmlspecialchars ($values[$this->name], ENT_QUOTES); $res .= htmlspecialchars ($this->values, ENT_QUOTES);
else else
$res .= htmlspecialchars ($this->defaults, ENT_QUOTES); $res .= htmlspecialchars ($this->defaults, ENT_QUOTES);
$res .= "</textarea>\n"; $res .= "</textarea>\n";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " <span class='help-block'>".$errors[$this->name][1]. $res .= " <span class='help-block'>".$this->errors[1].
"</span>\n"; "</span>\n";
$res .= " </div>\n"; // End controls $res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group $res .= " </div>\n"; // End form-group
@@ -599,8 +605,8 @@ class formfield
$res = ""; $res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols // No $this->multiple, $this->titles, $this->rows, $this->cols
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " has-".$errors[$this->name][0]; $res .= " has-".$this->errors[0];
$res .= "'>\n"; $res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='". $res .= " <label class='col-sm-2 control-label' for='".
$this->formName."_"; $this->formName."_";
@@ -620,8 +626,8 @@ class formfield
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$res .= " id='$this->formName"."_"; $res .= " id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."'"; $res .= htmlspecialchars ($this->name, ENT_QUOTES)."'";
if (isset ($values[$this->name])) if (isset ($this->values))
$res .= " value='".htmlspecialchars ($values[$this->name], $res .= " value='".htmlspecialchars ($this->values,
ENT_QUOTES)."'"; ENT_QUOTES)."'";
else else
$res .= " value='".htmlspecialchars ($this->defaults, ENT_QUOTES). $res .= " value='".htmlspecialchars ($this->defaults, ENT_QUOTES).
@@ -632,8 +638,8 @@ class formfield
if (isset ($this->hidden) && $this->hidden !== FALSE) if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'"; $res .= " style='display:none'";
$res .= "/>\n"; $res .= "/>\n";
if (isset ($errors[$this->name])) if (isset ($this->errors))
$res .= " <span class='help-block'>".$errors[$this->name][1]. $res .= " <span class='help-block'>".$this->errors[1].
"</span>\n"; "</span>\n";
$res .= " </div>\n"; // End controls $res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group $res .= " </div>\n"; // End form-group