Back to the module list

Create HTML Forms

The form is the based method to communicate with the users, and to get information. The created form is compatible with the Bootstrap library

Create a HTML form

$form = new \form ();
$values = array ();
$errors = array ();
$values = $form->getOldValues ($values);
$errors = $form->getOldErrors ($errors);

$fields = array ();

// Define the fields to display
$field = new \formfield ("requesterMail", _("Requester mail"));
$field->type = "hidden";
$fields[] = $field;

$field = new \formfield ("visitedName", _("Your name"));
$field->values = "default value";
$field->mandatory = true;
$field->maxlength = 128;
$fields[] = $field;

$form->fields ($fields);
echo $form->printHTML ("post", $values, $errors);

Get the values

$route = new route ();
$form = new \form ();
$values = $form->values ();
// Here check the values
$errors = array ();
$form->saveValuesErrors ($values, $errors);
if (count ($errors)) $route->redirect ("/request");
$requestObj->create ($values);
$form->saveValuesErrorsReset ();
$route->redirect ("/request");


The Form class blocks the user when it try to submit multiple times the form page. This is a working bug in Edge and Chrome.

The second point of security is a CSRF token automatically added to the page. If the token received by the POST is invalid, the request is rejected.