/** * 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."); }
<?php // Include CForm include '../../autoloader.php'; // ----------------------------------------------------------------------- // // Use the form and check it status. // session_name('cform_example'); session_start(); $form = new \Mos\HTMLForm\CForm(array('legend' => 'Legend'), array('search-widget' => array('type' => 'search-widget', 'description' => 'Here you can place a description.', 'placeholder' => 'Here is a placeholder', 'label' => 'Search', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmit(): Search-widget was submitted.</i></p>"); $form->AddOutput("<p><pre>" . print_r($_POST, 1) . "</pre></p>"); $form->saveInSession = true; return true; }))); // 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']); } else { if ($status === false) { $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); } } ?>
<?php // Include CForm include '../../autoloader.php'; // ----------------------------------------------------------------------- // // Use the form and check it status. // session_name('cform_example'); session_start(); $form = new \Mos\HTMLForm\CForm(array('legend' => 'Legend'), array('text' => array('type' => 'text', 'description' => 'Here you can place a description.', 'placeholder' => 'Here is a placeholder'), 'password' => array('type' => 'password', 'description' => 'Here you can place a description.', 'placeholder' => 'Here is a placeholder'), 'hidden' => array('type' => 'hidden', 'value' => 'secret value'), 'file' => array('type' => 'file', 'description' => 'Here you can place a description.'), 'textarea' => array('type' => 'textarea', 'description' => 'Here you can place a description.', 'placeholder' => 'Here is a placeholder'), 'radio' => array('type' => 'radio', 'label' => 'What is your preferred choice of fruite?', 'description' => 'Here you can place a description.', 'values' => array('tomato', 'potato', 'apple', 'pear', 'banana'), 'checked' => 'potato'), 'checkbox' => array('type' => 'checkbox', 'description' => 'Here you can place a description.'), 'select' => array('type' => 'select', 'label' => 'Select your fruite:', 'description' => 'Here you can place a description.', 'options' => array('tomato' => 'tomato', 'potato' => 'potato', 'apple' => 'apple', 'pear' => 'pear', 'banana' => 'banana'), 'value' => 'potato'), 'selectm' => array('type' => 'select-multiple', 'label' => 'Select your fruite:', 'description' => 'Here you can place a description.', 'size' => 6, 'options' => array('tomato' => 'tomato', 'potato' => 'potato', 'apple' => 'apple', 'pear' => 'pear', 'banana' => 'banana'), 'values' => array('potato', 'pear')), 'reset' => array('type' => 'reset'), 'button' => array('type' => 'button'), 'submit' => array('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><pre>" . print_r($_POST, 1) . "</pre></p>"); $form->saveInSession = true; return true; }), 'submit-fail' => array('type' => 'submit', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>"); return false; }))); // 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']); } else { if ($status === false) { $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); } }
} } */ // ----------------------------------------------------------------------- // // Use the form and check it status. // session_name('cform_example'); session_start(); $form = new \Mos\HTMLForm\CForm(array(), array('name' => array('type' => 'text', 'label' => 'Name of contact person:', 'required' => true, 'validation' => array('not_empty')), 'email' => array('type' => 'text', 'required' => true, 'validation' => array('not_empty', 'email_adress')), 'phone' => array('type' => 'text', 'required' => true, 'validation' => array('not_empty', 'numeric')), 'submit' => array('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>"); $form->AddOutput("<p><b>Phone: " . $form->Value('phone') . "</b></p>"); $form->saveInSession = true; return true; }), 'submit-fail' => array('type' => 'submit', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>"); return false; }))); // 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']); } else { if ($status === false) { $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']);
<?php // Get environment & autoloader. require __DIR__ . '/config.php'; // ----------------------------------------------------------------------- // // Use the form and check it status. // session_name('cform_example'); session_start(); $form = new \Mos\HTMLForm\CForm(); $form->create(array('legend' => 'Legend'), array('search-widget' => array('type' => 'search-widget', 'description' => 'Here you can place a description.', 'placeholder' => 'Here is a placeholder', 'label' => 'Search', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmit(): Search-widget was submitted.</i></p>"); $form->AddOutput("<p><pre>" . print_r($_POST, 1) . "</pre></p>"); $form->saveInSession = true; return true; }))); // 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']); } else { if ($status === false) { $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); } } ?>
VISA 4xxxxx 13, 16 MasterCard 51xxxx-55xxxx 16 Discover 6011xx 16 */ // ----------------------------------------------------------------------- // // Use the form and check it status. // session_name('cform_example'); session_start(); $currentYear = date('Y'); $elements = array('payment' => array('type' => 'hidden', 'value' => 10), 'name' => array('type' => 'text', 'label' => 'Name on credit card:', 'required' => true, 'autofocus' => true, 'validation' => array('not_empty')), 'address' => array('type' => 'text', 'required' => true, 'validation' => array('not_empty')), 'zip' => array('type' => 'text', 'required' => true, 'validation' => array('not_empty')), 'city' => array('type' => 'text', 'required' => true, 'validation' => array('not_empty')), 'country' => array('type' => 'select', 'options' => array('default' => 'Select a country...', 'no' => 'Norway', 'se' => 'Sweden'), 'validation' => array('not_empty', 'not_equal' => 'default')), 'cctype' => array('type' => 'select', 'label' => 'Credit card type:', 'options' => array('default' => 'Select a credit card type...', 'visa' => 'VISA', 'mastercard' => 'Mastercard', 'eurocard' => 'Eurocard', 'amex' => 'American Express'), 'validation' => array('not_empty', 'not_equal' => 'default')), 'ccnumber' => array('type' => 'text', 'label' => 'Credit card number:', 'validation' => array('not_empty', 'custom_test' => array('message' => 'Credit card number is not valid, try using 4408 0412 3456 7893 or 4417 1234 5678 9113 :-).', 'test' => 'isValidCCNumber'))), 'expmonth' => array('type' => 'select', 'label' => 'Expiration month:', 'options' => array('default' => 'Select credit card expiration month...', '01' => 'January', '02' => 'February', '03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December'), 'validation' => array('not_empty', 'not_equal' => 'default')), 'expyear' => array('type' => 'select', 'label' => 'Expiration year:', 'options' => array('default' => 'Select credit card expiration year...', $currentYear => $currentYear, ++$currentYear => $currentYear, ++$currentYear => $currentYear, ++$currentYear => $currentYear, ++$currentYear => $currentYear, ++$currentYear => $currentYear), 'validation' => array('not_empty', 'not_equal' => 'default')), 'cvc' => array('type' => 'text', 'label' => 'CVC:', 'required' => true, 'validation' => array('not_empty', 'numeric')), 'doPay' => array('type' => 'submit', 'value' => 'Perform payment', 'callback' => function ($form) { // Taking some money from the creditcard. 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']); } else { if ($status === false) { $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); } } $columns = isset($_GET['cols']) && $_GET['cols'] == 2 ? 2 : 1; ?>
<?php // Include CForm include '../../autoloader.php'; // Start the session session_name('cform_example'); session_start(); // Sample form $form = new \Mos\HTMLForm\CForm([], ['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'], 'submit-fail' => ['type' => 'submit']]); // Check the status of the form $status = $form->check(function ($form) { // What to do if the form was submitted? $form->AddOutput("<p><i>Form was submitted and the callback method returned true.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); }, function ($form) { // What to do when form could not be processed? $form->AddOutput("<p><i>Form was submitted and check() method returned false.</i></p>"); header("Location: " . $_SERVER['PHP_SELF']); }); $title = "Test issue 13"; ?> <!doctype html> <meta charset=utf8> <title><?php echo $title; ?> </title> <h1><?php
$addend = $digit; } $sum += $addend; $timesTwo = !$timesTwo; } return $sum % 10 == 0; } $app->router->add('form/creditcard', function () use($app) { $app->session; $form = $app->form; $currentYear = date('Y'); $elements = array('payment' => array('type' => 'hidden', 'value' => 10), 'name' => array('type' => 'text', 'label' => 'Name on credit card:', 'required' => true, 'autofocus' => true, 'validation' => array('not_empty')), 'address' => array('type' => 'text', 'required' => true, 'validation' => array('not_empty')), 'zip' => array('type' => 'text', 'required' => true, 'validation' => array('not_empty')), 'city' => array('type' => 'text', 'required' => true, 'validation' => array('not_empty')), 'country' => array('type' => 'select', 'options' => array('default' => 'Select a country...', 'no' => 'Norway', 'se' => 'Sweden'), 'validation' => array('not_empty', 'not_equal' => 'default')), 'cctype' => array('type' => 'select', 'label' => 'Credit card type:', 'options' => array('default' => 'Select a credit card type...', 'visa' => 'VISA', 'mastercard' => 'Mastercard', 'eurocard' => 'Eurocard', 'amex' => 'American Express'), 'validation' => array('not_empty', 'not_equal' => 'default')), 'ccnumber' => array('type' => 'text', 'label' => 'Credit card number:', 'validation' => array('not_empty', 'custom_test' => array('message' => 'Credit card number is not valid, try using 4408 0412 3456 7893 or 4417 1234 5678 9113 :-).', 'test' => 'isValidCCNumber'))), 'expmonth' => array('type' => 'select', 'label' => 'Expiration month:', 'options' => array('default' => 'Select credit card expiration month...', '01' => 'January', '02' => 'February', '03' => 'March', '04' => 'April', '05' => 'May', '06' => 'June', '07' => 'July', '08' => 'August', '09' => 'September', '10' => 'October', '11' => 'November', '12' => 'December'), 'validation' => array('not_empty', 'not_equal' => 'default')), 'expyear' => array('type' => 'select', 'label' => 'Expiration year:', 'options' => array('default' => 'Select credit card expiration year...', $currentYear => $currentYear, ++$currentYear => $currentYear, ++$currentYear => $currentYear, ++$currentYear => $currentYear, ++$currentYear => $currentYear, ++$currentYear => $currentYear), 'validation' => array('not_empty', 'not_equal' => 'default')), 'cvc' => array('type' => 'text', 'label' => 'CVC:', 'required' => true, 'validation' => array('not_empty', 'numeric')), 'doPay' => array('type' => 'submit', 'value' => 'Perform payment', 'callback' => function ($form) { // Taking some money from the creditcard. 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) {
session_start(); // Get selected validation rules $rules = array('not_empty', 'numeric', 'email_adress'); $validation = array(); if (!empty($_POST['tests'])) { foreach ($_POST['tests'] as $val) { if (in_array($val, $rules)) { $validation[] = $val; } } } $form = new \Mos\HTMLForm\CForm(array(), array('enter-a-value' => array('type' => 'text'), 'tests' => array('type' => 'checkbox-multiple', 'description' => 'Choose the validation rules to use.', 'values' => $rules), 'submit' => array('type' => 'submit', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmit(): Nothing to do.</i></p>"); //$form->AddOutput("<pre>" . print_r($_POST, 1) . "</pre>"); $form->saveInSession = true; return true; }), 'submit-fail' => array('type' => 'submit', 'callback' => function ($form) { $form->AddOutput("<p><i>DoSubmitFail(): Form was submitted but I failed to process/save/validate it</i></p>"); return false; }))); // Set the active validation rules $form->SetValidation('enter-a-value', $validation); // 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']); } else { if ($status === false) { $form->AddOutput("<p><i>Form was submitted and the Check() method returned false.</i></p>");