(almost) real life depage-forms example
(almost) real life depage-forms exampleContains a common personal information form. Some elements are set required and the username has a minimum length.
<?php
require_once '../../HtmlForm.php';
$dataFieldset = $form->addFieldset('dataFieldset', ['label' => 'Personal Information']);
$dataFieldset->addText('firstName', ['label' => 'First name']);
$dataFieldset->addText('lastName', ['label' => 'Last name']);
$dataFieldset->addText('userName', ['label' => 'User name', 'required' => true, 'validator' => '/.{6,}/', 'title' => 'at least 6 characters']);
$dataFieldset->addEmail('email', ['label' => 'Email address', 'required' => true]);
$dataFieldset->addSingle('language', [
'label' => 'Language',
'skin' => 'select',
'list' => [
'en' => 'English',
'es' => 'Spanish',
'fr' => 'French',
'de' => 'German',
],
]);
$checkFieldset = $form->addFieldset('checkFieldset', ['label' => 'Terms and Conditions']);
$checkFieldset->addBoolean('read', ['label' => 'I have read and understood the terms and conditions.', 'required' => true]);
$checkFieldset->addBoolean('accept', ['label' => 'Accept terms and conditions.', 'required' => true]);
$form->process();
if ($form->validate()) {
echo('<a href="">back</a>');
echo('<pre>');
var_dump($form->getValues());
echo('</pre>');
$data = $form->getValues();
$username = $data['userName'];
$form->clearSession();
} else {
?>
<!DOCTYPE html>
<head>
<link rel="stylesheet" type="text/css" href="../../lib/css/depage-forms.css">
</head>
<body>
<?php echo($form); ?>
</body>
<?php
}