/** * Test * * @return void * */ public function testCreate1() { $form = new \Mos\HTMLForm\CForm(); $form->create(); $res = $form->getHTML(); $exp = <<<EOD <form method='post'> <fieldset> </fieldset> </form> EOD; $this->assertEquals($res, $exp, "Empty form render missmatch."); }
return true; })); $form = new \Mos\HTMLForm\CForm(array(), $elements); // Check the status of the form $status = $form->Check(); // What to do if the form was submitted? if ($status === true) { $form->AddOUtput("<p><i>Form was submitted and the callback method returned true.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); } elseif ($status === false) { // What to do when form could not be processed? $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); } $app->theme->setTitle("Creditcard checkout"); $app->views->add('welcome/page', ['title' => "CForm Example: Creditcard checkout", 'content' => $form->getHTML()]); }); $app->router->add('form/searchwidget', function () use($app) { $app->session; $form = $app->form; $form = new \Mos\HTMLForm\CFMSearchWidget(); $form->Check(); $app->theme->setTitle("Search widget"); $app->views->add('welcome/page', ['title' => "Example: Search widget", 'content' => $form->getHTML()]); }); // Test form route $app->router->add('test1', function () use($app) { $form = $app->form->create([], ['name' => ['type' => 'text', 'label' => 'Name of contact person:', 'required' => true, 'validation' => ['not_empty']], 'email' => ['type' => 'text', 'required' => true, 'validation' => ['not_empty', 'email_adress']], 'phone' => ['type' => 'text', 'required' => true, 'validation' => ['not_empty', 'numeric']], 'submit' => ['type' => 'submit', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmit(): Form was submitted. Do stuff (save to database) and return true (success) or false (failed processing form)</i></p>"); $form->AddOutput("<p><b>Name: " . $form->Value('name') . "</b></p>"); $form->AddOutput("<p><b>Email: " . $form->Value('email') . "</b></p>");