<?php require_once '../../src/autoload.php'; require_once '../../vendor/autoload.php'; $form = new \X2Form\Form('ContactForm', ['action' => 'example10.php', 'method' => 'post']); $form->addStep(['index' => 1, 'name' => 'step1', 'label' => 'Step 1:', 'description' => 'User Data', 'elements' => [['type' => 'text', 'name' => 'NAME', 'label' => 'Your Name', 'mandatory' => true, 'value' => 'Rudra'], ['type' => 'text', 'name' => 'EMAIL', 'label' => 'Your Email', 'mandatory' => true, 'datatype' => 'email', 'ifempty' => 'Please provide email address.', 'ifinvalid' => 'The email address you provided is invalid.']]]); $form->addStep(['index' => 2, 'name' => 'step2', 'label' => 'Step 2:', 'description' => 'Personal Information', 'elements' => [['type' => 'radio', 'name' => 'GENDER', 'label' => 'Gender', 'mandatory' => true, 'options' => ['array' => ['male', 'female']]], ['type' => 'checkbox', 'name' => 'LANGUAGES', 'label' => 'Languages known', 'mandatory' => true, 'options' => ['array' => ['English', 'Hindi', 'French', 'German']], 'direction' => 'vertical']]]); $form->addStep(['index' => 3, 'name' => 'step3', 'label' => 'Step 3:', 'description' => 'Personal Information', 'elements' => [['type' => 'dropdown', 'name' => 'EXPERIENCE', 'label' => 'Experience', 'mandatory' => true, 'options' => ['array' => ['fresher', '6 months+', '1 year', '2 years', '3 years', '4 years', '5 years', '5-10 years', '10-15 years', '15+ years']], 'value' => '1 year'], ['type' => 'collection', 'name' => 'work_experience', 'label' => 'Work Experience', 'from' => [['type' => 'text', 'name' => 'company', 'label' => 'Company', 'mandatory' => true], ['type' => 'text', 'name' => 'role', 'label' => 'Role', 'mandatory' => true]]]]]); $form->addStep(['index' => 4, 'name' => 'step4', 'label' => 'Step 4:', 'description' => 'Are you Human?', 'elements' => [['type' => 'captcha', 'name' => 'CAPTCHA', 'secret' => 'blahblah']]]); $form->addGroup(['name' => 'buttons', 'direction' => 'inline', 'elements' => [['type' => 'submit', 'name' => 'submit', 'value' => 'Submit'], ['type' => 'reset', 'name' => 'reset', 'value' => 'Reset']]]); $form->finalize(); $form->renderer = new X2Form\Renderers\Bootstrap\Renderer(); //handle the form submission if (isset($_POST['submit']) && $_POST['submit'] == "Submit") { $log = $form->processSubmission($_POST); if (!logg_ok($log)) { $message = '<p class="text-danger">' . logg_msg($log) . '</p>'; $form->rollBackFileUploads(); } else { $message = '<p class="text-success">' . logg_msg($log) . '</p>'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Example 10 - Implementing Steps using bootstrap</title> <!-- HERE WE INCLUDE BOOTSTRAP CSS -->
<?php require_once '../../src/autoload.php'; require_once '../../vendor/autoload.php'; $form = new \X2Form\Form('ContactForm', ['action' => 'example5.php', 'method' => 'post']); $form->addText(['name' => 'NAME', 'label' => 'Your Name', 'mandatory' => true, 'value' => 'Rudra']); $form->addText(['name' => 'EMAIL', 'label' => 'Your Email', 'mandatory' => true, 'datatype' => 'email']); $form->addRadio(['name' => 'GENDER', 'label' => 'Gender', 'mandatory' => true, 'options' => ['array' => ['male', 'female']]]); $form->addDropdown(['name' => 'EXPERIENCE', 'label' => 'Experience', 'mandatory' => true, 'options' => ['array' => ['fresher', '6 months+', '1 year', '2 years', '3 years', '4 years', '5 years', '5-10 years', '10-15 years', '15+ years']], 'value' => '1 year']); $form->addTextarea(['name' => 'MESSAGE', 'label' => 'Message', 'rows' => '4', 'cols' => '50', 'mandatory' => true]); $form->addCollection(['name' => 'work_experience', 'label' => 'Work Experience', 'from' => [['type' => 'text', 'name' => 'company', 'label' => 'Company', 'mandatory' => true], ['type' => 'text', 'name' => 'role', 'label' => 'Role', 'mandatory' => true]]]); $form->addCaptcha(['name' => 'CAPTCHA', 'secret' => 'blahblah']); $form->addGroup(['name' => 'buttons', 'direction' => 'inline', 'elements' => [['type' => 'submit', 'name' => 'submit', 'value' => 'Submit'], ['type' => 'reset', 'name' => 'reset', 'value' => 'Reset']]]); //we can also populate fields from php using setValues() method of the X2Form class $values = array('work_experience' => array(array('company' => 'Possible Solutions', 'role' => 'Junior Developer'), array('company' => 'Tech Revolution', 'role' => 'Senior Developer')), 'GENDER' => 'male'); $form->setValues($values); //Alternatively we can also populate individual fields directly $form->elements['EMAIL']->value = '*****@*****.**'; //array syntax $form->elements->MESSAGE->value = "I am Rudra!"; //this syntax works as well $form->finalize(); //handle the form submission if (isset($_POST['submit']) && $_POST['submit'] == "Submit") { $log = $form->processSubmission($_POST); if (!logg_ok($log)) { $message = '<div class="error">' . logg_msg($log) . '</div>'; $form->rollBackFileUploads(); } else { $message = '<div class="success">' . logg_msg($log) . '</div>'; }
<?php require_once '../../src/autoload.php'; require_once '../../vendor/autoload.php'; $form = new \X2Form\Form('ContactForm', ['action' => 'example4.php', 'method' => 'post']); $form->addText(['name' => 'NAME', 'label' => 'Your Name', 'mandatory' => true]); $form->addText(['name' => 'EMAIL', 'label' => 'Your Email', 'mandatory' => true, 'datatype' => 'email']); $form->addTextarea(['name' => 'MESSAGE', 'label' => 'Message', 'rows' => '4', 'cols' => '50', 'mandatory' => true]); $form->addCollection(['name' => 'work_experience', 'label' => 'Work Experience', 'from' => [['type' => 'text', 'name' => 'company', 'label' => 'Company', 'mandatory' => true], ['type' => 'text', 'name' => 'role', 'label' => 'Role', 'mandatory' => true]]]); $form->addCaptcha(['name' => 'CAPTCHA', 'secret' => 'blahblah']); $form->addGroup(['name' => 'buttons', 'direction' => 'inline', 'elements' => [['type' => 'submit', 'name' => 'submit', 'value' => 'Submit'], ['type' => 'reset', 'name' => 'reset', 'value' => 'Reset']]]); $form->finalize(); //handle the form submission if (isset($_POST['submit']) && $_POST['submit'] == "Submit") { $log = $form->processSubmission($_POST); if (!logg_ok($log)) { $message = '<div class="error">' . logg_msg($log) . '</div>'; $form->rollBackFileUploads(); } else { $message = '<div class="success">' . logg_msg($log) . '</div>'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Example 4 - Constructing a form in example 3 using only PHP calls(using add* methods)</title> <link href="../css/style.css" type="text/css" rel="stylesheet"> <script type="text/javascript" src="../js/jquery-ui-1.9.2.custom/js/jquery-1.8.3.js" ></script> </head>
<?php require_once '../../src/autoload.php'; require_once '../../vendor/autoload.php'; $form = new \X2Form\Form('ContactForm', ['action' => 'example2.php', 'method' => 'post', 'elements' => [['type' => 'text', 'name' => 'NAME', 'label' => 'Your Name', 'mandatory' => true], ['type' => 'text', 'name' => 'EMAIL', 'label' => 'Your Email', 'mandatory' => true, 'datatype' => 'email'], ['type' => 'textarea', 'name' => 'MESSAGE', 'label' => 'Message', 'rows' => '4', 'cols' => '50', 'mandatory' => true], ['type' => 'captcha', 'name' => 'CAPTCHA', 'secret' => 'blahblah'], ['type' => 'group', 'name' => 'buttons', 'direction' => 'inline', 'elements' => [['type' => 'submit', 'name' => 'submit', 'value' => 'Submit'], ['type' => 'reset', 'name' => 'reset', 'value' => 'Reset']]]]]); $form->finalize(); //handle the form submission if (isset($_POST['submit']) && $_POST['submit'] == "Submit") { $log = $form->processSubmission($_POST); if (!logg_ok($log)) { $message = '<div class="error">' . logg_msg($log) . '</div>'; $form->rollBackFileUploads(); } else { $message = '<div class="success">' . logg_msg($log) . '</div>'; } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Example 2 - Group</title> <link href="../css/style.css" type="text/css" rel="stylesheet"> </head> <body> <div id="outputContainer"> <div class="container"> <h2>Sample Contact Us Form</h2> <?php //lets print the submitted data if the validation was successful
<?php require_once '../../src/autoload.php'; require_once '../../vendor/autoload.php'; $link = mysql_connect('localhost', 'root', ''); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db('test', $link); if (!$db_selected) { die('Can\'t select database : ' . mysql_error()); } //FIRST_NAME, LAST_NAME and PROFESSION is populated from xml $formObj = new \X2Form\Form('QuidichForm', ['from' => 'forms/quidich_form_grouped.xml', 'renderer' => new X2Form\Renderers\Bootstrap\Renderer(), 'action' => 'example3.php']); $formObj->attributes['action'] = 'example3.php'; $formObj->elements['FAMILY_MEMBERS']->setValues(array(0 => array('FIRST_NAME' => 'sameer'), 1 => array('LAST_NAME' => 'test'))); $formObj->finalize(); if (isset($_POST['submit']) && $_POST['submit'] == "Submit") { $log = $formObj->processSubmission($_POST); if (!logg_ok($log)) { $message = '<div class="error">' . logg_msg($log) . '</div>'; $formObj->rollBackFileUploads(); } else { $message = '<div class="success">' . logg_msg($log) . '</div>'; } } elseif (isset($_REQUEST['captcha']) && $_REQUEST['captcha'] == 'refresh') { echo $formObj->renderer->elementRenderer->refreshCaptcha($formObj->elements['captcha']); exit; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"