diff --git a/form.php b/form.php
index ba6d0b4..c55d1c8 100644
--- a/form.php
+++ b/form.php
@@ -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 .= " hidden) && $this->hidden !== FALSE)
@@ -783,7 +804,7 @@ class formfield
$res .= " \n";
}
$res .= "
\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 .= "
\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 .= "
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 .= "
\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 .= "
\n"; // End form-group
+ return $res;
+ }
+ // }}}
+
+ /** Return the checkbox defined
+ */
+ private function fieldBootstrap4select ()
+ // {{{
+ {
+ // No $this->placeholder $this->maxlength
+ $res = "";
+ // $values->$this, $this->cols
+ $res .= "
\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 .= "
\n";
+ return $res;
+ }
+ // }}}
+
+ /** Return the textarea defined
+ */
+ private function fieldBootstrap4textarea ()
+ // {{{
+ {
+ $res = "";
+ // No $this->multiple, $this->titles
+ $res .= "
\n"; // End form-group
+ return $res;
+ }
+ // }}}
+
+ /** Return the text defined
+ */
+ private function fieldBootstrap4text ()
+ // {{{
+ {
+ $res = "";
+ // No $this->multiple, $this->titles, $this->rows, $this->cols
+ $res .= "
\n"; // End form-group
+ return $res;
+ }
+ // }}}
+
+ /** Return the file defined
+ */
+ private function fieldBootstrap4file ()
+ // {{{
+ {
+ $res = "";
+ // No $this->multiple, $this->titles, $this->rows, $this->cols
+ $res .= "
\n"; // End form-group
+ return $res;
+ }
+ // }}}
+
+ // }}}
}