form: add 'file' type to upload

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@4180 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2018-03-28 11:23:39 +00:00
parent 3b74f55a2d
commit c81a7f3e2f

View File

@@ -257,6 +257,16 @@ class form
$this->method = strtolower ($method);
$res = "";
$res = "<form action='#' method='$method'";
// If a file field will be displayed, the form must have a
// enctype="multipart/form-data" parameter
foreach ($this->fields as $field)
{
if ($field->type === "file")
{
$res .= "enctype='multipart/form-data'";
break;
}
}
if ($this->formName != "")
$res .= " id='$this->formName'";
$res .= " class='".$this->formClass."'>\n";
@@ -572,7 +582,7 @@ class formfield
*/
public function hidden ($val)
{
$this->type = !! $val;
$this->hidden = !! $val;
return $this;
}
@@ -1247,4 +1257,86 @@ class formfield
$res .= " </div>\n"; // End form-group
return $res;
}
/** Return the file defined */
public function fieldfile ()
{
$res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols
$res .= "<div class='form-group";
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label class='col-sm-$this->titlewidth control-label' for='".
$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."'";
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
$res .= ">";
$res .= htmlspecialchars ($this->label);
if (isset ($this->mandatory) && $this->mandatory !== FALSE)
$res .= " <span style='color:red'>*</span>";
else
$res .= " ";
$res .= "</label>\n";
}
$res .= " <div class='col-sm-$this->fieldwidth'>\n";
if (isset ($this->defaults))
{
$res .= " <label class='btn btn-default col-sm-$this->fieldwidth'>\n";
$res .= htmlspecialchars ($this->defaults, ENT_QUOTES);
}
$res .= " <input type='file'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]";
if (isset ($this->multiple) && $this->multiple !== false)
$res .= "[]";
$res .= "'";
$res .= " id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."'";
if (isset ($this->values))
$res .= " value='".htmlspecialchars ($this->values,
ENT_QUOTES)."'";
else
$res .= " value='".htmlspecialchars ($this->defaults, ENT_QUOTES).
"'";
if (isset ($this->readonly) && $this->readonly !== FALSE)
$res .= " readonly='readonly'";
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
if (isset ($this->cols))
$res .= " size='".$this->cols."'";
if (isset ($this->maxlength))
$res .= " maxlength='".$this->maxlength."'";
if (isset ($this->errors) || isset ($this->help))
{
$res .= " aria-describedby='".$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'";
}
if (isset ($this->placeholder) && $this->placeholder !== FALSE)
$res .= " placeholder='".htmlentities ($this->placeholder, ENT_QUOTES).
"'";
if (isset ($this->multiple) && $this->multiple !== false)
$res .= " multiple='multiple'";
$res .= "/>\n";
if (isset ($this->defaults))
$res .= " </label>\n"; // End labels
if (isset ($this->errors) || isset ($this->help))
{
$res .= " <span class='help-block' id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>";
if (isset ($this->help))
$res .= "<span class='text-muted'>".$this->help."</span>";
if (isset ($this->help) && isset ($this->errors))
$res .= "<br/>";
if (isset ($this->errors)) $res .= $this->errors[1];
$res .= "</span>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
}