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:
85
form.php
85
form.php
@@ -52,15 +52,12 @@ class form
|
||||
- [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
|
||||
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
|
||||
- [hidden] : hide the field (add a style='display:hidden' to the field)
|
||||
- [prefix] : the prefix added to the name (in XXX/YYY/ZZZ form).
|
||||
Will form an array to the result
|
||||
- [rows] : Number of rows
|
||||
- [cols] : Number of columns
|
||||
|
||||
@param array $fields The fields to be displayed
|
||||
*/
|
||||
@@ -116,49 +113,11 @@ class form
|
||||
checked
|
||||
@param array $fieldsVerify The fields to verify
|
||||
@param array|null $valuesVerify The values of the fields to verify
|
||||
@deprecated 0.17
|
||||
*/
|
||||
public function verify (&$fieldsVerify, $valuesVerify = NULL)
|
||||
{
|
||||
// TODO : Remove this function or be cleaner !
|
||||
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;
|
||||
die ("FORM/VERIFY : UNUSED and deprecated\n");
|
||||
}
|
||||
|
||||
/** 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)
|
||||
{
|
||||
case "checkbox":
|
||||
// No $field->multiple
|
||||
// No $field->multiple, $field->rows $field->cols
|
||||
// values !
|
||||
$res .= "<div class='form-group";
|
||||
if (isset ($errors[$field->name]))
|
||||
@@ -263,7 +222,8 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
|
||||
break;
|
||||
|
||||
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 .= " name='$this->formName"."[";
|
||||
if (isset ($field->prefix))
|
||||
@@ -281,7 +241,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
|
||||
break;
|
||||
|
||||
case "password":
|
||||
// No $field->multiple
|
||||
// No $field->multiple, $field->rows $field->cols
|
||||
$res .= "<div class='form-group";
|
||||
if (isset ($errors[$field->name]))
|
||||
$res .= " has-".$errors[$field->name][0];
|
||||
@@ -330,7 +290,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
|
||||
break;
|
||||
|
||||
case "radio":
|
||||
// No $field->multiple
|
||||
// No $field->multiple, $field->rows $field->cols
|
||||
$res .= "<div class='form-group";
|
||||
if (isset ($errors[$field->name]))
|
||||
$res .= " has-".$errors[$field->name][0];
|
||||
@@ -396,7 +356,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
|
||||
break;
|
||||
|
||||
case "select":
|
||||
// $values->$field
|
||||
// $values->$field, $field->cols
|
||||
$res .= "<div class='form-group";
|
||||
if (isset ($errors[$field->name]))
|
||||
$res .= " has-".$errors[$field->name][0];
|
||||
@@ -463,6 +423,8 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
|
||||
if (isset ($field->hidden) && $field->hidden !== FALSE)
|
||||
$res .= " style='display:none'";
|
||||
$res .= " class='form-control'";
|
||||
if (isset ($field->rows))
|
||||
$res .= " size='".$field->rows."'";
|
||||
$res .= ">\n";
|
||||
foreach ($field->defaults as $key=>$val)
|
||||
{
|
||||
@@ -496,7 +458,8 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
|
||||
break;
|
||||
|
||||
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='col-sm-12'>\n";
|
||||
$res .= " <input type='submit'";
|
||||
@@ -558,6 +521,12 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
|
||||
$res .= " class='form-control'";
|
||||
if (isset ($field->hidden) && $field->hidden !== FALSE)
|
||||
$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 .= ">";
|
||||
if (isset ($values[$field->name]))
|
||||
$res .= htmlspecialchars ($values[$field->name], ENT_QUOTES);
|
||||
@@ -572,7 +541,7 @@ die ("FORM/VERIFY : UNUSED and dirty\n");
|
||||
break;
|
||||
|
||||
default:
|
||||
// No $field->multiple, $field->titles
|
||||
// No $field->multiple, $field->titles, $field->rows, $field->cols
|
||||
$res .= "<div class='form-group";
|
||||
if (isset ($errors[$field->name]))
|
||||
$res .= " has-".$errors[$field->name][0];
|
||||
@@ -668,11 +637,17 @@ class formfield
|
||||
public $group;
|
||||
/** The read-only feature of the field */
|
||||
public $readonly;
|
||||
/** The fonction used to verify the field by AJAX before submitting and
|
||||
by PHP after submission*/
|
||||
public $verify;
|
||||
/** The field is mandatory */
|
||||
public $mandatory;
|
||||
/** The statut of error of the field */
|
||||
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
|
||||
@param string $name Name of the field
|
||||
@param string $label Label of the field */
|
||||
|
||||
Reference in New Issue
Block a user