form : allow to define the bootstrap width for titles and fields columns

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2223 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-08-07 12:54:16 +00:00
parent 35f2002e3f
commit 25632eb4c8

View File

@@ -26,6 +26,11 @@ class form
/** The method used to send the values */
private $method = "post";
/** The Bootstrap width of the column of titles */
public $titlewidth = 2;
/** The Bootstrap width of the column of fields */
public $fieldswidth = 10;
/** Create a form
@param string|null $formName The form name
*/
@@ -188,6 +193,8 @@ class form
if (isset ($errors[$field->name]) &&
$errors[$field->name] !== "unset")
$field->errors = $errors[$field->name];
$field->titlewidth = $this->titlewidth;
$field->fieldwidth = $this->fieldwidth;
$res .= $field->display ();
}
@@ -250,6 +257,10 @@ class formfield
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 $fieldswidth = 10;
/** When adding a field, the name and the label are the minimum mandatory
@param string $name Name of the field
@param string $label Label of the field */
@@ -275,7 +286,7 @@ class formfield
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
$res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='".
$res .= " <label class='col-sm-$this->titlewidth control-label' for='".
$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES);
if (count ($this->titles) > 1)
@@ -290,7 +301,7 @@ class formfield
else
$res .= " ";
$res .= "</label>\n";
$res .= " <div class='col-sm-10'>\n";
$res .= " <div class='col-sm-$this->fieldswidth'>\n";
if (count ($this->titles) === 0)
$this->titles = array ("");
foreach ($this->titles as $key=>$val)
@@ -401,7 +412,7 @@ class formfield
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
$res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='".
$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)
@@ -413,7 +424,7 @@ class formfield
else
$res .= " ";
$res .= "</label>\n";
$res .= " <div class='col-sm-10'>\n";
$res .= " <div class='col-sm-$this->fieldswidth'>\n";
$res .= " <input type='password'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
@@ -461,7 +472,7 @@ class formfield
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
$res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='".
$res .= " <label class='col-sm-$this->titlewidth control-label' for='".
$this->formName."_";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."_0'";
if (isset ($this->hidden) && $this->hidden !== FALSE)
@@ -473,7 +484,7 @@ class formfield
else
$res .= " ";
$res .= "</label>\n";
$res .= " <div class='col-sm-10'>\n";
$res .= " <div class='col-sm-$this->fieldswidth'>\n";
if (is_string ($this->defaults))
$this->defaults = array ($this->defaults);
$res .= " <input type='hidden'";
@@ -535,7 +546,7 @@ class formfield
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
$res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='".
$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)
@@ -547,7 +558,7 @@ class formfield
else
$res .= " ";
$res .= "</label>\n";
$res .= " <div class='col-sm-10'>\n";
$res .= " <div class='col-sm-$this->fieldswidth'>\n";
if (isset ($this->defaults) && is_array ($this->defaults))
{
if (isset ($this->readonly) && $this->readonly !== FALSE)
@@ -640,7 +651,8 @@ class formfield
// No $this->label, $this->multiple, $this->error, $this->rows,
// $this->cols
$res .= "<div class='form-group'>\n";
$res .= " <div class='col-sm-12'>\n";
$res .= " <div class='col-sm-".($this->titlewidth+$this->fieldswidth).
"'>\n";
$res .= " <input type='submit'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
@@ -671,7 +683,7 @@ class formfield
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
$res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='".
$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)
@@ -683,7 +695,7 @@ class formfield
else
$res .= " ";
$res .= "</label>\n";
$res .= " <div class='col-sm-10'>\n";
$res .= " <div class='col-sm-$this->fieldswidth'>\n";
$res .= " <textarea";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";
@@ -734,7 +746,7 @@ class formfield
if (isset ($this->errors))
$res .= " has-".$this->errors[0];
$res .= "'>\n";
$res .= " <label class='col-sm-2 control-label' for='".
$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)
@@ -746,7 +758,7 @@ class formfield
else
$res .= " ";
$res .= "</label>\n";
$res .= " <div class='col-sm-10'>\n";
$res .= " <div class='col-sm-$this->fieldswidth'>\n";
$res .= " <input type='text'";
$res .= " name='$this->formName"."[";
$res .= htmlspecialchars ($this->name, ENT_QUOTES)."]'";