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