/** * Makes sure that alle Field Displays are updated before a string * representation of the Form containing those Fields are returned * * @return string */ public function __toString() { foreach ($this->dataSource->getFields() as $field) { $field->refreshDisplay(); /* Make sure that all hidden fields will be displayed somewhere */ if ($field instanceof \Feeld\Field\CommonProperties\IdentifierInterface && $field->hasId() && is_null($this->getChildById($field->getId()))) { $fieldDisplay = $field->getDisplay(); if ($fieldDisplay instanceof Input && isset($fieldDisplay->attributes['type']) && $fieldDisplay->attributes['type'] === 'hidden') { $this->prependChild($field->getDisplay()); } } } return parent::__toString(); }
/** * Constructor * * @param string $type text, url, number, email, image, submit, date, search, etc. */ public function __construct($type) { parent::__construct('input'); $this->setAttribute('type', $type); }
$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>
public function __construct() { parent::__construct('select'); }
/** * Constructor */ public function __construct($type = 'submit') { parent::__construct('button'); $this->setAttribute('type', $type); }
public function __construct() { parent::__construct('textarea'); }