Files
DomFramework/src/Formfield.php
2023-04-14 20:52:27 +02:00

1875 lines
68 KiB
PHP

<?php
/**
* DomFramework
* @package domframework
* @author Dominique Fournier <dominique@fournier38.fr>
* @license BSD
*/
namespace Domframework;
/**
* The definition of a formfield
*/
class Formfield
{
/**
* The form name
*/
public $formName;
/**
* The name of the field
*/
public $name;
/**
* The label of the field
*/
public $label;
/**
* The titles of the field
*/
public $titles;
/**
* The defaults values of the field
*/
public $defaults;
/**
* The type of the field (text, password, checkbox, select)
*/
public $type = "text";
/**
* The state of the field : hidden or show
*/
public $hidden = false;
/**
* Allow a help message to be displayed below the field. In case of error,
* it is overrided by the error message
*/
public $help;
/**
* Display the placeholder if needed
*/
public $placeholder = false;
/**
* The multiplicity of selection of the field (available in select only)
*/
public $multiple;
/**
* The name of group for the fields
*/
public $group;
/**
* The read-only feature of the field
*/
public $readonly;
/**
* The field is mandatory
*/
public $mandatory;
/**
* The statut of error of the field
*/
public $error;
/**
* Number of rows
*/
public $rows;
/**
* Number of columns
*/
public $cols;
/**
* The Bootstrap width of the column of titles
*/
public $titlewidth = 2;
/**
* The Bootstrap width of the column of fields
*/
public $fieldwidth = 10;
/**
* Form template (Bootstrap3 by default)
*/
private $formTemplate = "Bootstrap3";
/**
* When adding a field, the name and the label are the minimum mandatory
* @param string $name Name of the field
* @param string|null $label Label of the field
*/
public function __construct($name, $label = "")
{
$this->name = $name;
$this->label = $label;
}
/**
* Display really the form
*/
public function display()
{
$func = "field" . $this->formTemplate . $this->type;
return $this->$func();
}
// Setters for all the properties of the class
/**
* Set the type of the field
* @param string $val The value of the type of the field
*/
public function type($val)
{
$this->type = $val;
return $this;
}
/**
* Set the hidden of the field
* @param string $val The value of the hidden of the field
*/
public function hidden($val)
{
$this->hidden = !! $val;
return $this;
}
/**
* Set the help of the field
* @param string $val The value of the help of the field
*/
public function help($val)
{
$this->help = $val;
return $this;
}
/**
* Set the placeholder
* @param string $val The value of the placeholder
*/
public function placeholder($val)
{
$this->placeholder = $val;
return $this;
}
/**
* Set the multiple
* @param string $val The value of the multiple
*/
public function multiple($val)
{
$this->multiple = $val;
return $this;
}
/**
* Set the group
* @param string $val The value of the group
*/
public function group($val)
{
$this->group = $val;
return $this;
}
/**
* Set the readonly
* @param string $val The value of the readonly
*/
public function readonly($val)
{
$this->readonly = !! $val;
return $this;
}
/**
* Set the mandatory
* @param string $val The value of the mandatory
*/
public function mandatory($val)
{
$this->mandatory = !! $val;
return $this;
}
/**
* Set the rows
* @param string $val The value of the rows
*/
public function rows($val)
{
$this->rows = $val;
return $this;
}
/**
* Set the cols
* @param string $val The value of the cols
*/
public function cols($val)
{
$this->cols = $val;
return $this;
}
//////////////////////////
//// BOOTSTRAP3 ////
//////////////////////////
/**
* Return the checkbox defined
*/
private function fieldBootstrap3checkbox()
{
// No $this->multiple, $this->rows $this->cols $this->placeholder,
// $this->maxlength
if (! is_array($this->titles) || count($this->titles) === 0) {
$titles = [""];
} else {
$titles = $this->titles;
}
$res = "";
$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'";
if (
is_array($this->titles) && count($this->titles) == 1 &&
reset($this->titles) === ""
) {
// If more than one title is set, the main label is unusable, so
// do not link it to the checkbox
// If there is no label on the checkbox, this label must be set
$res .= " for='" . $this->formName . "_";
$res .= htmlspecialchars($this->name, ENT_QUOTES);
$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";
foreach ($titles as $key => $val) {
$res .= " <div class='checkbox'>\n";
$res .= " <input type='hidden'";
$res .= " name='$this->formName" . "[";
$res .= htmlspecialchars($this->name, ENT_QUOTES) . "]";
if (count($titles) > 1) {
$res .= "[$key]";
}
$res .= "' value='unset'";
$res .= "/>";
$res .= "<label for='$this->formName" . "_";
$res .= htmlspecialchars($this->name, ENT_QUOTES);
if (count($titles) > 1) {
$res .= "_$key";
}
$res .= "'>";
$res .= "<input type='checkbox'";
$res .= " name='$this->formName" . "[";
$res .= htmlspecialchars($this->name, ENT_QUOTES) . "]";
if (count($titles) > 1) {
$res .= "[$key]";
}
$res .= "' id='$this->formName" . "_";
$res .= htmlspecialchars($this->name, ENT_QUOTES);
if (count($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($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'";
}
if (isset($this->errors) || isset($this->help)) {
$res .= " aria-describedby='" . $this->formName . "_";
$res .= htmlspecialchars($this->name, ENT_QUOTES) . "_help'";
}
$res .= "/>";
$res .= "$val</label>\n";
$res .= "</div>\n";
}
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 .= htmlspecialchars($this->errors[1]);
}
$res .= "</span>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
/**
* Return the hidden field defined
*/
private function fieldBootstrap3hidden()
{
$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 fieldBootstrap3password()
{
$res = "";
// No $this->multiple, $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";
$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->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) .
"'";
}
$res .= "/>\n";
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 .= htmlspecialchars($this->errors[1]);
}
$res .= "</span>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
/**
* Return the radio field defined
*/
private function fieldBootstrap3radio()
{
$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];
}
$res .= "'>\n";
if ($this->label !== "") {
$res .= " <label class='col-sm-$this->titlewidth control-label'";
if (
is_array($this->titles) && count($this->titles) == 1 &&
reset($this->titles) === ""
) {
// If more than one title is set, the main label is unusable, so
// do not link it to the radio
// If there is no label on the checkbox, this label must be set
$res .= " for='" . $this->formName . "_";
$res .= htmlspecialchars($this->name, ENT_QUOTES);
$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_string($this->defaults)) {
$this->defaults = [$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='radio'>";
$res .= " <label>";
$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'";
}
if (isset($this->errors) || isset($this->help)) {
$res .= " aria-describedby='" . $this->formName . "_";
$res .= htmlspecialchars($this->name, ENT_QUOTES) . "_help'";
}
$res .= "/>";
$res .= "$val";
$res .= "</label>\n"; // End label radio
$res .= "</div>";
}
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 .= htmlspecialchars($this->errors[1]);
}
$res .= "</span>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
/**
* Return the checkbox defined
*/
private function fieldBootstrap3select()
{
// No $this->placeholder $this->maxlength
$res = "";
// $values->$this, $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) && 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->rows)) {
$res .= " size='" . $this->rows . "'";
}
if (isset($this->errors) || 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, true)
) {
$res .= " selected='selected'";
}
$res .= ">";
$res .= htmlspecialchars($val);
$res .= "</option>\n";
}
$res .= " </select>\n";
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 .= htmlspecialchars($this->errors[1]);
}
$res .= "</span>\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 fieldBootstrap3submit()
{
$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 fieldBootstrap3textarea()
{
$res = "";
// No $this->multiple, $this->titles
$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";
$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->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->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) .
"'";
}
$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) || 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 .= htmlspecialchars($this->errors[1]);
}
$res .= "</span>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
/**
* Return the text defined
*/
private function fieldBootstrap3text()
{
$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";
$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->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) .
"'";
}
$res .= "/>\n";
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 .= htmlspecialchars($this->errors[1]);
}
$res .= "</span>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
/**
* Return the file defined
*/
private function fieldBootstrap3file()
{
$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'";
}
$res .= " class='form-control'";
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 .= htmlspecialchars($this->errors[1]);
}
$res .= "</span>\n";
}
$res .= " </div>\n"; // End controls
$res .= " </div>\n"; // End form-group
return $res;
}
//////////////////////////
//// BOOTSTRAP4 ////
//////////////////////////
/**
* Return the checkbox defined
*/
private function fieldBootstrap4checkbox()
{
// No $this->multiple, $this->rows $this->cols $this->placeholder,
// $this->maxlength
if (! is_array($this->titles) || count($this->titles) === 0) {
$this->titles = [""];
}
$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'";
}
if (
is_array($this->titles) && count($this->titles) == 1 &&
reset($this->titles) === ""
) {
// If more than one title is set, the main label is unusable, so
// do not link it to the checkbox
// If there is no label on the checkbox, this label must be set
$res .= " for='" . $this->formName . "_";
$res .= htmlspecialchars($this->name, ENT_QUOTES);
$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";
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'";
}
if (
is_array($this->titles) && count($this->titles) == 1 &&
reset($this->titles) === ""
) {
// If more than one title is set, the main label is unusable, so
// do not link it to the radio
// If there is no label on the checkbox, this label must be set
$res .= " for='" . $this->formName . "_";
$res .= htmlspecialchars($this->name, ENT_QUOTES);
$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_string($this->defaults)) {
$this->defaults = [$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, true)
) {
$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;
}
}