Exemple #1
0
$formUI = (new HTML\Form('post'))->addCssClass('form-horizontal');
$errorDiv = new HTML\ErrorContainer();
$successDiv = (new Div())->addCssClass('has-success')->setContent('<p>Your blog entry was submitted!</p>');
$formUI->appendChildren($nicknameUI, $emailUI, $textUI);
$formUI->appendChild((new HTML\Button('submit'))->setContent('Publish!'));
// Putting data model and UI together
$formForBlogPost->setDisplay($formUI);
$formForBlogPost->setFieldDisplay('nickname', $nicknameUI);
$formForBlogPost->setFieldDisplay('email', $emailUI);
$formForBlogPost->setFieldDisplay('text', $textUI);
$validationErrors->setDisplay($errorDiv);
// The Interviewer "HTMLForm" is executed
$htmlForm = new Interview\HTMLForm(0, $validationErrors, $formForBlogPost);
$htmlForm->setSuccessDisplay($successDiv);
$htmlForm->execute();
// Display error messages first, in case something goes wrong
print $validationErrors;
// Display success message on successful form submission
print $successDiv;
// Display form fields (if applicable)
print $htmlForm->getCurrentCollection();
// Proof that it worked (not really necessary)
if ($htmlForm->getStatus() === Interview\InterviewInterface::STATUS_AFTER_INTERVIEW) {
    $article = new HTML\Element('article');
    $article->addCssClass('blog');
    $article->appendChild((new HTML\Element('h2'))->setContent('Most recent blog post'));
    $article->appendChild(new HTML\TextNode(nl2br($htmlForm->getCurrentValidAnswers())));
    print $article;
}
?>
</body></html>