form : add the cols,rows and prefix for fields

git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@2166 bf3deb0d-5f1a-0410-827f-c0cc1f45334c
This commit is contained in:
2015-05-12 09:03:24 +00:00
parent 0b3d621317
commit a17171e83a

View File

@@ -52,15 +52,12 @@ class form
- [readonly] : put a read-only flag on the field (the user see it but - [readonly] : put a read-only flag on the field (the user see it but
can't interract on it. The value will be sent to next can't interract on it. The value will be sent to next
page page
- [verify] : Tests to verify with error priority and associated
message (%s is replaced by field selected value). Order
test from main tests to minor tests.
\$tmpfield can be used as a copy of the current field,
to check the defaults per example
- [mandatory] : boolean to add a red star at end of label - [mandatory] : boolean to add a red star at end of label
- [hidden] : hide the field (add a style='display:hidden' to the field) - [hidden] : hide the field (add a style='display:hidden' to the field)
- [prefix] : the prefix added to the name (in XXX/YYY/ZZZ form). - [prefix] : the prefix added to the name (in XXX/YYY/ZZZ form).
Will form an array to the result Will form an array to the result
- [rows] : Number of rows
- [cols] : Number of columns
@param array $fields The fields to be displayed @param array $fields The fields to be displayed
*/ */
@@ -116,49 +113,11 @@ class form
checked checked
@param array $fieldsVerify The fields to verify @param array $fieldsVerify The fields to verify
@param array|null $valuesVerify The values of the fields to verify @param array|null $valuesVerify The values of the fields to verify
@deprecated 0.17
*/ */
public function verify (&$fieldsVerify, $valuesVerify = NULL) public function verify (&$fieldsVerify, $valuesVerify = NULL)
{ {
// TODO : Remove this function or be cleaner ! die ("FORM/VERIFY : UNUSED and deprecated\n");
die ("FORM/VERIFY : UNUSED and dirty\n");
$ret = array ();
if ($this->debug)
echo "<pre>";
foreach ($fieldsVerify as $field)
{
if (!isset ($field->verify))
continue;
if (!isset ($valuesVerify[$field->name]))
throw new Exception ("No value provided for $field->name", 500);
foreach ($field->verify as $test => $message)
{
$func = sprintf ($test, addslashes ($valuesVerify[$field->name]));
if ($this->debug)
echo "VERIFY: \"$func\" => ";
$tmpfield = $field;
$res = addslashes (serialize ($tmpfield));
// TODO : http://fr2.php.net/manual/en/reflectionfunction.invokeargs.php
// to remove eval ?
$rc = eval ("\$tmpfield=unserialize(stripslashes('$res'));".
"return $func;");
if ($this->debug)
var_dump ($rc);
if ($rc !== FALSE)
{
$ret[$field->name] = $message;
$field->error = $message;
break;
}
}
}
if ($this->debug)
{
echo "RESULT: ";
var_dump ($ret);
echo "</pre>";
}
return $ret;
} }
/** Return the fields in HTML code. If $values is provided, use it in place /** Return the fields in HTML code. If $values is provided, use it in place
@@ -199,7 +158,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
switch ($field->type) switch ($field->type)
{ {
case "checkbox": case "checkbox":
// No $field->multiple // No $field->multiple, $field->rows $field->cols
// values ! // values !
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$field->name])) if (isset ($errors[$field->name]))
@@ -263,7 +222,8 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
break; break;
case "hidden": case "hidden":
// No $field->label, $field->multiple, $field->readonly, $field->hidden // No $field->label, $field->multiple, $field->readonly, $field->hidden,
// $field->rows $field->cols
$res .= "<input type='hidden'"; $res .= "<input type='hidden'";
$res .= " name='$this->formName"."["; $res .= " name='$this->formName"."[";
if (isset ($field->prefix)) if (isset ($field->prefix))
@@ -281,7 +241,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
break; break;
case "password": case "password":
// No $field->multiple // No $field->multiple, $field->rows $field->cols
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$field->name])) if (isset ($errors[$field->name]))
$res .= " has-".$errors[$field->name][0]; $res .= " has-".$errors[$field->name][0];
@@ -330,7 +290,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
break; break;
case "radio": case "radio":
// No $field->multiple // No $field->multiple, $field->rows $field->cols
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$field->name])) if (isset ($errors[$field->name]))
$res .= " has-".$errors[$field->name][0]; $res .= " has-".$errors[$field->name][0];
@@ -396,7 +356,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
break; break;
case "select": case "select":
// $values->$field // $values->$field, $field->cols
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$field->name])) if (isset ($errors[$field->name]))
$res .= " has-".$errors[$field->name][0]; $res .= " has-".$errors[$field->name][0];
@@ -463,6 +423,8 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
if (isset ($field->hidden) && $field->hidden !== FALSE) if (isset ($field->hidden) && $field->hidden !== FALSE)
$res .= " style='display:none'"; $res .= " style='display:none'";
$res .= " class='form-control'"; $res .= " class='form-control'";
if (isset ($field->rows))
$res .= " size='".$field->rows."'";
$res .= ">\n"; $res .= ">\n";
foreach ($field->defaults as $key=>$val) foreach ($field->defaults as $key=>$val)
{ {
@@ -496,7 +458,8 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
break; break;
case "submit": case "submit":
// No $field->label, $field->multiple, $field->error // No $field->label, $field->multiple, $field->error, $field->rows,
// $field->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-12'>\n";
$res .= " <input type='submit'"; $res .= " <input type='submit'";
@@ -558,6 +521,12 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
$res .= " class='form-control'"; $res .= " class='form-control'";
if (isset ($field->hidden) && $field->hidden !== FALSE) if (isset ($field->hidden) && $field->hidden !== FALSE)
$res .= " style='display:none'"; $res .= " style='display:none'";
if (!isset ($field->cols))
$field->cols = 20;
$res .= " cols='".$field->cols."'";
if (!isset ($field->rows))
$field->rows = 4;
$res .= " rows='".$field->rows."'";
$res .= ">"; $res .= ">";
if (isset ($values[$field->name])) if (isset ($values[$field->name]))
$res .= htmlspecialchars ($values[$field->name], ENT_QUOTES); $res .= htmlspecialchars ($values[$field->name], ENT_QUOTES);
@@ -572,7 +541,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
break; break;
default: default:
// No $field->multiple, $field->titles // No $field->multiple, $field->titles, $field->rows, $field->cols
$res .= "<div class='form-group"; $res .= "<div class='form-group";
if (isset ($errors[$field->name])) if (isset ($errors[$field->name]))
$res .= " has-".$errors[$field->name][0]; $res .= " has-".$errors[$field->name][0];
@@ -668,11 +637,17 @@ class formfield
public $group; public $group;
/** The read-only feature of the field */ /** The read-only feature of the field */
public $readonly; public $readonly;
/** The fonction used to verify the field by AJAX before submitting and /** The field is mandatory */
by PHP after submission*/ public $mandatory;
public $verify;
/** The statut of error of the field */ /** The statut of error of the field */
public $error; public $error;
/** the prefix added to the name (in XXX/YYY/ZZZ form). Will form an array to
the result */
public $prefix;
/** Number of rows */
public $rows;
/** Number of columns */
public $cols;
/** 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 */