form : Add Bootstrap4 support (change formThemplate to select). Bootstrap 3 always the default one

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5614 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2019-10-23 12:26:10 +00:00
parent fdaa4dee05
commit e48f541c61

831
form.php
View File

@@ -57,6 +57,10 @@ class form
*/
private $loggingBasemsg = "";
/** Form template (Bootstrap3 by default)
*/
private $formTemplate = "Bootstrap3";
/** Create a form
* @param string|null $formName The form name
*/
@@ -143,6 +147,18 @@ class form
$this->loggingCallable = $loggingCallable;
$this->loggingBasemsg = $loggingBasemsg;
}
/** Set the Form Templating to use.
* Can be : Bootstrap3 (and later Bootstrap4, Bulma)
*/
public function formTemplate ($formTemplate)
{
if (! in_array ($formTemplate,
array ("Bootstrap3", "Bootstrap4")))
throw new \Exception ("Unknown formTemplate provided", 500);
$this->formTemplate = $formTemplate;
return $this;
}
// }}}
/** The private method to log if the $this->loggingCallable is defined
@@ -352,6 +368,7 @@ class form
}
$field->titlewidth = $this->titlewidth;
$field->fieldwidth = $this->fieldwidth;
$field->formTemplate = $this->formTemplate;
$res .= $field->display ();
}
@@ -654,7 +671,7 @@ class formfield
public function display ()
// {{{
{
$func = "field".$this->type;
$func = "field".$this->formTemplate.$this->type;
return $this->$func ();
}
// }}}
@@ -752,9 +769,13 @@ class formfield
}
// }}}
//////////////////////////
//// BOOTSTRAP3 ////
//////////////////////////
// {{{
/** Return the checkbox defined
*/
public function fieldcheckbox ()
private function fieldBootstrap3checkbox ()
// {{{
{
// No $this->multiple, $this->rows $this->cols $this->placeholder,
@@ -769,7 +790,7 @@ class formfield
$res .= " <label class='col-sm-$this->titlewidth control-label' for='".
$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
if (count ($this->titles) > 1)
if (is_array ($this->titles) && count ($this->titles) > 1)
$res .= "_0";
$res .= "'";
if (isset ($this->hidden) && $this->hidden !== FALSE)
@@ -783,7 +804,7 @@ class formfield
$res .= "</label>\n";
}
$res .= " <div class='col-sm-$this->fieldwidth'>\n";
if (count ($this->titles) === 0)
if (! is_array ($this->titles) || count ($this->titles) === 0)
$this->titles = array ("");
foreach ($this->titles as $key=>$val)
{
@@ -880,7 +901,7 @@ class formfield
/** Return the hidden field defined
*/
public function fieldhidden ()
private function fieldBootstrap3hidden ()
// {{{
{
$res = "";
@@ -902,7 +923,7 @@ class formfield
/** Return the password field defined
*/
public function fieldpassword ()
private function fieldBootstrap3password ()
// {{{
{
$res = "";
@@ -976,7 +997,7 @@ class formfield
/** Return the radio field defined
*/
public function fieldradio ()
private function fieldBootstrap3radio ()
// {{{
{
$res = "";
@@ -1060,7 +1081,7 @@ class formfield
/** Return the checkbox defined
*/
public function fieldselect ()
private function fieldBootstrap3select ()
// {{{
{
// No $this->placeholder $this->maxlength
@@ -1186,7 +1207,7 @@ class formfield
/** Return the submit defined
*/
public function fieldsubmit ()
private function fieldBootstrap3submit ()
// {{{
{
$res = "";
@@ -1229,7 +1250,7 @@ class formfield
/** Return the textarea defined
*/
public function fieldtextarea ()
private function fieldBootstrap3textarea ()
// {{{
{
$res = "";
@@ -1306,7 +1327,7 @@ class formfield
/** Return the text defined
*/
public function fieldtext ()
private function fieldBootstrap3text ()
// {{{
{
$res = "";
@@ -1380,7 +1401,7 @@ class formfield
/** Return the file defined
*/
public function fieldfile ()
private function fieldBootstrap3file ()
// {{{
{
$res = "";
@@ -1464,4 +1485,790 @@ class formfield
return $res;
}
// }}}
// }}}
//////////////////////////
//// BOOTSTRAP4 ////
//////////////////////////
// {{{
/** Return the checkbox defined
*/
private function fieldBootstrap4checkbox ()
// {{{
{
// No $this->multiple, $this->rows $this->cols $this->placeholder,
// $this->maxlength
$res = "";
$res .= "<div class='form-group";
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
if ($this->titlewidth > 0)
$res .= " row";
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label";
if ($this->titlewidth > 0)
$res .= " class='col-sm-$this->titlewidth col-form-label'";
$res .= " for='". $this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
if (is_array ($this->titles) && count ($this->titles) > 1)
$res .= "_0";
$res .= "'";
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 (! is_array ($this->titles) || count ($this->titles) === 0)
$this->titles = array ("");
foreach ($this->titles as $key=>$val)
{
$res .= " <div class='form-check'>\n";
$res .= " <input type='hidden'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]";
if (count ($this->titles) > 1)
$res .= "[$key]";
$res .= "' value='unset'";
$res .= "/>\n";
$res .= " <input type='checkbox'";
$res .= " name='$this->formName"."[";
$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'";
// Do not check by default !
// Check is enable if not null and not false and not "unset" and not ""
if (count ($this->titles) === 1)
{
if (isset ($this->values) &&
$this->values !== null &&
$this->values !== false &&
$this->values !== "unset" &&
$this->values !== "")
$res .= " checked='checked'";
elseif (isset ($this->defaults) &&
$this->defaults !== null &&
$this->defaults !== false &&
$this->defaults !== "unset" &&
$this->defaults !== "")
$res .= " checked='checked'";
}
else
{
if (isset ($this->values[$key]))
{
if ($this->values[$key] !== null &&
$this->values[$key] !== false &&
$this->values[$key] !== "unset" &&
$this->values[$key] !== "")
$res .= " checked='checked'";
}
elseif (isset ($this->defaults[$key]))
{
if ($this->defaults[$key] !== null &&
$this->defaults[$key] !== false &&
$this->defaults[$key] !== "unset" &&
$this->defaults[$key] !== "")
$res .= " checked='checked'";
}
}
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
$res .= " class='form-check-input";
if (isset ($this->errors))
{
$res .= " is-invalid";
}
$res .= "'";
if (isset ($this->help))
{
$res .= " aria-describedby='".$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'";
}
$res .= "/>\n";
$res .= " <label for='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_";
if (count ($this->titles) > 1)
$res .= "$key";
$res .= "' class ='form-check-label'";
$res .= ">";
$res .= "$val</label>\n";
if (isset ($this->errors) && $key === count ($this->titles) - 1)
{
$res .= " <div class='invalid-feedback'>";
$res .= htmlspecialchars ($this->errors[1]);
$res .= "</div>\n";
}
$res .= " </div>\n";
}
if (isset ($this->help))
{
$res .= " <small class='form-text text-muted' ";
$res .= "id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>";
$res .= $this->help;
$res .= "</small>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
// }}}
/** Return the hidden field defined
*/
private function fieldBootstrap4hidden ()
// {{{
{
$res = "";
// No $this->label, $this->multiple, $this->readonly, $this->hidden,
// $this->rows $this->cols $this->placeholder $this->maxlength
$res .= "<input type='hidden'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$res .= " id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."'";
if (isset ($this->values))
$res .= " value='".htmlspecialchars ($this->values)."'";
else
$res .= " value='".htmlspecialchars ($this->defaults)."'";
$res .= "/>\n";
return $res;
}
// }}}
/** Return the password field defined
*/
private function fieldBootstrap4password ()
// {{{
{
$res = "";
// No $this->multiple, $this->rows $this->cols
$res .= "<div class='form-group";
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
if ($this->titlewidth > 0)
$res .= " row";
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label";
if ($this->titlewidth > 0)
$res .= " class='col-sm-$this->titlewidth col-form-label'";
$res .= " 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";
$res .= " <input type='password'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$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'";
$res .= " class='form-control";
if (isset ($this->errors))
$res .= " is-invalid";
$res .= "'";
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->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).
"'";
$res .= "/>\n";
if (isset ($this->errors))
{
$res .= " <div class='invalid-feedback'>";
$res .= htmlspecialchars ($this->errors[1]);
$res .= "</div>\n";
}
if (isset ($this->help))
{
$res .= " <small class='form-text text-muted' ";
$res .= "id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>";
$res .= $this->help;
$res .= "</small>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
// }}}
/** Return the radio field defined
*/
private function fieldBootstrap4radio ()
// {{{
{
$res = "";
// No $this->multiple, $this->rows $this->cols $this->placeholder
// $this->maxlength
$res .= "<div class='form-group";
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
if ($this->titlewidth > 0)
$res .= " row";
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label";
if ($this->titlewidth > 0)
$res .= " class='col-sm-$this->titlewidth col-form-label'";
$res .= " for='". $this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_0'";
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 (is_string ($this->defaults))
$this->defaults = array ($this->defaults);
$res .= " <input type='hidden'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$res .= " value='unset'";
$res .= "/>\n";
foreach ($this->titles as $key=>$val)
{
$res .= " <div class='form-check'>\n";
$res .= " <input type='radio'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$res .= " id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_$key'";
$res .= " value='".htmlspecialchars ($val, ENT_QUOTES)."'";
if (isset ($this->readonly) && $this->readonly !== FALSE)
$res .= " readonly='readonly'";
if (isset ($this->values) &&
$this->values === $val)
$res .= " checked='checked'";
elseif (isset ($this->defaults[0]) &&
$this->defaults[0] === $val)
$res .= " checked='checked'";
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
$res .= " class='form-check-input";
if (isset ($this->errors))
$res .= " is-invalid";
$res .= "'";
if (isset ($this->help))
{
$res .= " aria-describedby='".$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'";
}
$res .= "/>\n";
$res .= " <label class='form-check-label'>";
$res .= "$val";
$res .= "</label>\n"; // End label radio
if (isset ($this->errors) && $key === count ($this->titles) - 1)
{
$res .= " <div class='invalid-feedback'>";
$res .= htmlspecialchars ($this->errors[1]);
$res .= "</div>\n";
}
$res .= " </div>\n";
}
if (isset ($this->help))
{
$res .= " <small class='form-text text-muted' ";
$res .= "id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>";
$res .= $this->help;
$res .= "</small>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
// }}}
/** Return the checkbox defined
*/
private function fieldBootstrap4select ()
// {{{
{
// No $this->placeholder $this->maxlength
$res = "";
// $values->$this, $this->cols
$res .= "<div class='form-group";
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
if ($this->titlewidth > 0)
$res .= " row";
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label";
if ($this->titlewidth > 0)
$res .= " class='col-sm-$this->titlewidth col-form-label'";
$res .= " 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) && is_array ($this->defaults))
{
if (isset ($this->readonly) && $this->readonly !== FALSE)
{
foreach ($this->defaults as $key=>$val)
{
$res .= " <input type='hidden'";
if (isset ($this->multiple) && $this->multiple !== FALSE)
{
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."][".
htmlspecialchars ($key, ENT_QUOTES)."]'";
}
else
{
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
}
$res .= " value='";
$res .= htmlspecialchars ($key, ENT_QUOTES)."'";
$res .= "/>\n";
}
}
$res .= " <select";
$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->multiple) && $this->multiple !== FALSE)
$res .= " multiple='multiple'";
if (isset ($this->readonly) && $this->readonly !== FALSE)
$res .= " disabled='disabled'";
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
$res .= " class='form-control";
if (isset ($this->errors))
$res .= " is-invalid";
$res .= "'";
if (isset ($this->rows))
$res .= " size='".$this->rows."'";
if (isset ($this->help))
{
$res .= " aria-describedby='".$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'";
}
$res .= ">\n";
foreach ($this->defaults as $key=>$val)
{
if (! is_string ($val))
{
throw new \Exception ("Value as defaut for $this->name::$key is not ".
"a string (".gettype ($val).")");
}
$res .= " <option value='";
$res .= htmlspecialchars ($key, ENT_QUOTES)."'";
if (isset ($this->values) &&
is_string ($this->values) &&
$this->values == $key)
$res .= " selected='selected'";
elseif (isset ($this->values) &&
is_integer ($this->values) &&
$this->values == $key)
$res .= " selected='selected'";
elseif (isset ($this->values) &&
is_array ($this->values) &&
in_array ($key, $this->values))
$res .= " selected='selected'";
$res .= ">";
$res .= htmlspecialchars ($val);
$res .= "</option>\n";
}
$res .= " </select>\n";
if (isset ($this->errors))
{
$res .= " <div class='invalid-feedback'>";
$res .= htmlspecialchars ($this->errors[1]);
$res .= "</div>\n";
}
if (isset ($this->help))
{
$res .= " <small class='form-text text-muted' ";
$res .= "id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>";
$res .= $this->help;
$res .= "</small>\n";
}
}
else
{
$res .= dgettext ("domframework", "No value provided");
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
// }}}
/** Return the submit defined
*/
private function fieldBootstrap4submit ()
// {{{
{
$res = "";
// No $this->label, $this->multiple, $this->error, $this->rows,
// $this->cols $this->placeholder $this->maxlength
$res .= "<div class='form-group'>\n";
$res .= " <div class='col-sm-".($this->titlewidth+$this->fieldwidth).
"'>\n";
$res .= " <input type='submit'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$res .= " id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."'";
if (isset ($this->readonly) && $this->readonly !== FALSE)
$res .= " disabled='disabled'";
if (isset ($this->defaults))
$res .= " value='".htmlspecialchars ($this->defaults, ENT_QUOTES).
"'";
elseif (isset ($this->label))
$res .= " value='".htmlspecialchars ($this->label, ENT_QUOTES)."'";
$res .= " class='form-control btn-primary'";
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
// Block the submit button 10s. The user can not double click on it and
// submit two times the POST to the server
// Re-enable after 15s, if there is a problem with the server
// This code is needed by Chrome and Edge which allow multiple submission of
// a form
$res .= " onclick='submit=this ; ";
$res .= " setTimeout(function() {";
$res .= " submit.setAttribute(\"disabled\", \"disabled\");";
$res .= " }, 1);";
$res .= "'";
$res .= "/>\n";
$res .= " </div>\n";
$res .= " </div>\n";
return $res;
}
// }}}
/** Return the textarea defined
*/
private function fieldBootstrap4textarea ()
// {{{
{
$res = "";
// No $this->multiple, $this->titles
$res .= "<div class='form-group";
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
if ($this->titlewidth > 0)
$res .= " row";
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label";
if ($this->titlewidth > 0)
$res .= " class='col-sm-$this->titlewidth col-form-label'";
$res .= " 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";
$res .= " <textarea";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$res .= " id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."'";
if (isset ($this->readonly) && $this->readonly !== FALSE)
$res .= " readonly='readonly'";
$res .= " class='form-control";
if (isset ($this->errors))
$res .= " is-invalid";
$res .= "'";
if (isset ($this->hidden) && $this->hidden !== FALSE)
$res .= " style='display:none'";
if (!isset ($this->cols))
$this->cols = 20;
$res .= " cols='".$this->cols."'";
if (!isset ($this->rows))
$this->rows = 4;
$res .= " rows='".$this->rows."'";
if (isset ($this->maxlength))
$res .= " maxlength='".$this->maxlength."'";
if (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).
"'";
$res .= ">";
if (isset ($this->values))
$res .= htmlspecialchars ($this->values, ENT_QUOTES);
else
$res .= htmlspecialchars ($this->defaults, ENT_QUOTES);
$res .= "</textarea>\n";
if (isset ($this->errors))
{
$res .= " <div class='invalid-feedback'>";
$res .= htmlspecialchars ($this->errors[1]);
$res .= "</div>\n";
}
if (isset ($this->help))
{
$res .= " <small class='form-text text-muted' ";
$res .= "id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>";
$res .= $this->help;
$res .= "</small>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
// }}}
/** Return the text defined
*/
private function fieldBootstrap4text ()
// {{{
{
$res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols
$res .= "<div class='form-group";
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
if ($this->titlewidth > 0)
$res .= " row";
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label";
if ($this->titlewidth > 0)
$res .= " class='col-sm-$this->titlewidth col-form-label'";
$res .= " 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";
$res .= " <input type='text'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
$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'";
$res .= " class='form-control";
if (isset ($this->errors))
$res .= " is-invalid";
$res .= "'";
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->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).
"'";
$res .= "/>\n";
if (isset ($this->errors))
{
$res .= " <div class='invalid-feedback'>";
$res .= htmlspecialchars ($this->errors[1]);
$res .= "</div>\n";
}
if (isset ($this->help))
{
$res .= " <small class='form-text text-muted' ";
$res .= "id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>";
$res .= $this->help;
$res .= "</small>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
// }}}
/** Return the file defined
*/
private function fieldBootstrap4file ()
// {{{
{
$res = "";
// No $this->multiple, $this->titles, $this->rows, $this->cols
$res .= "<div class='form-group";
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
if ($this->titlewidth > 0)
$res .= " row";
$res .= "'>\n";
if ($this->label !== "")
{
$res .= " <label";
if ($this->titlewidth > 0)
$res .= " class='col-sm-$this->titlewidth col-form-label'";
$res .= " 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'";
$res .= " class='form-control";
if (isset ($this->errors))
$res .= " is-invalid";
$res .= "'";
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->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))
{
$res .= " <div class='invalid-feedback'>";
$res .= htmlspecialchars ($this->errors[1]);
$res .= "</div>\n";
}
if (isset ($this->help))
{
$res .= " <small class='form-text text-muted' ";
$res .= "id='$this->formName"."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_help'>";
$res .= $this->help;
$res .= "</small>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
// }}}
// }}}
}