Populate form example.
Populate form exampleThe HtmlForm->populate method provides a comfortable way to fill in default values before displaying the form. It's more convenient than setting the 'defaultValue' parameter for each input element individually.
<?php
require_once '../../HtmlForm.php';
$form->addText('username', ['label' => 'User name']);
$form->addEmail('email', ['label' => 'Email address']);
$fieldset = $form->addFieldset('fieldset', ['label' => 'User name']);
$fieldset->addText('fieldsetText', ['label' => 'Text in fieldset']);
$form->populate(
[
'username' => 'depage',
'email' => 'mail@somedomain.org',
'fieldsetText' => 'It works!',
],
);
$form->process();
if ($form->validate()) {
echo('<a href="">back</a>');
echo('<pre>');
var_dump($form->getValues());
echo('</pre>');
$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
}