$labelNome = $form1->createField('label', ['text' => 'Nome', 'for' => 'inputNome']); $inputNome = $form1->createField('input', ['type' => 'text', 'name' => 'nome', 'id' => 'inputNome']); $labelValor = $form1->createField('label', ['text' => 'Valor', 'for' => 'inputValor']); $inputValor = $form1->createField('input', ['type' => 'text', 'name' => 'valor', 'id' => 'inputValor']); $labelDesc = $form1->createField('label', ['text' => 'Descrição', 'for' => 'inputDesc']); $inputDesc = $form1->createField('input', ['type' => 'text', 'name' => 'descricao', 'id' => 'inputDesc']); $select = $form1->createField('select', ['name' => 'categoria']); $pdo = new \PDO('sqlite:' . __DIR__ . "/../src/DB/db.sqlite", null, null, [\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION]); $stmt = $pdo->prepare("SELECT id, nome FROM categoria"); $stmt->execute(); while ($result = $stmt->fetch(\PDO::FETCH_OBJ)) { $op = $form1->createField('option', ['value' => $result->id, 'text' => $result->nome]); $select->addOption($op); } $inputSubmit = $form1->createField('input', ['type' => 'submit', 'value' => 'Enviar']); $form1->addField($labelNome)->addField($inputNome)->addField($labelValor)->addField($inputValor)->addField($labelDesc)->addField($inputDesc)->addField($select)->addField($inputSubmit); $fieldDefs = ['nome' => 'Sapato', 'valor' => 35, 'descricao' => 'Sapato preto']; $form1->populate($fieldDefs); ?> <!doctype html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <title>Design Patterns</title> </head> <body> <?php $form1->render(); ?> </body> </html>
<?php require_once __DIR__ . '/autoload.php'; use DP\Form; use DP\Types\Input; //Cria o Form $form = new Form(); //Cria o input Text $inputText = new Input(); $inputText->setTipo("text")->setName('Nome'); //Cria o input Time $inputTime = new Input(); $inputTime->setTipo("time")->setName('Data'); //Cria o input Submit $inputSubmit = new Input(); $inputSubmit->setTipo('submit'); //Adiciona os campos no objeto form $form->addField($inputText)->addField($inputTime)->addField($inputSubmit); ?> <html> <head> <title>Design Pattern</title> </head> <body> <!-- Renderiza o form --> <?php $form->render(); ?> </body> </html>
<?php require_once __DIR__ . "/../vendor/autoload.php"; use DP\Elements\Input; use DP\Form; $form1 = new Form(); $inputNome = new Input(['type' => 'text', 'name' => 'nome']); $inputSubmit = new Input(['type' => 'submit', 'value' => 'Enviar']); $form1->addField($inputNome)->addField($inputSubmit); ?> <!doctype html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <title>Design Patterns</title> </head> <body> <?php $form1->render(); ?> </body> </html>