Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.84 KB | None | 0 0
  1. <html>
  2. <link rel="stylesheet" type="text/css" href="/css/jformer.css"></link>
  3.  
  4. <script type="text/javascript" src="/js/jquery.js" ></script>
  5. <script type="text/javascript" src="/js/jFormer.js" ></script>
  6.  
  7. <?php
  8.     ini_set('display_errors',1);
  9.     error_reporting(E_ALL|E_STRICT);
  10.    
  11.  
  12.     require_once($_SERVER['DOCUMENT_ROOT'].'/jformer.php');
  13.    
  14.     // Create the form , This is the object which wraps and handles the form
  15.     // the ID of the form is passed as the first argument this will be used in DOM to help identify the form.
  16.     // you can pass an options array as a second argument, but we'll go over that later.
  17.     $demonstrationForm = new JFormer('demonstrationForm');
  18.    
  19.     // Create the form page
  20.     // this object is a page on the form, it holds the sections
  21.     // you can have as many pages as you want.
  22.     // again, the ID is passed first, and an option array is passed second,
  23.     $demonstrationPage = new JFormPage($demonstrationForm->id.'Page', array(
  24.         // Here we set the title of the Page and this can be straight text or HTML
  25.         'title' => '<h3>Address Component Examples</h3>',
  26.     ));
  27.    
  28.     // Create the form section
  29.     // again, the Id is passed as the first argument with an optional array of options
  30.     // sections holds all of your inputs, seperating inputs into sections allow for better organization.
  31.     // there can be multiple sections on a page.
  32.     $demonstrationSection = new JFormSection($demonstrationForm->id.'Section');
  33.    
  34.     // Add components to the section
  35.     $demonstrationSection->addJFormComponentArray(array(
  36.         // this is a single line text component, Id passed as the first argument, with the label passed as the second
  37.         // take a look at the options array passed as the third argument, options can be added in any order
  38.         new JFormComponentSingleLineText('text1', 'Say Hello:', array(
  39.             // this description is displayed under the field to give extra information
  40.             'description' => '<p>I am a description for a component, and can be used to give further instruction as needed. Put in your first name and click submit.</p>',
  41.             // these are all the validations this field needs to pass, you can have one, none or as many as you need!
  42.             'validationOptions' => array('required', 'alpha'),
  43.             // this is the tipe that shows up when this field has focus, it is great if you need to give hints or helpful information, but dont' need it always showing
  44.             'tip' => '<p>Hey look, I am a tip, and I can give helpful advice.</p><p>Please don\'t leave me blank, also I am set to only accept letters. try typing in a number and see what happens.</p>',
  45.         )),
  46.     ));
  47.    
  48.     // Add the section to the page (place it inside)
  49.     $demonstrationPage->addJFormSection($demonstrationSection);
  50.    
  51.     // Add the page to the form (place it inside)
  52.     $demonstrationForm->addJFormPage($demonstrationPage);
  53.    
  54.    
  55.     // Set the function for a successful form submission
  56.     // so if all validation passes on all form components, the data gets sent server side to be handled by this function, in this function is where you would want to put all your handling,
  57.     // whether that is talking to a database, checking of login credentials, here is the place you do with your data that gets submitted.
  58.     function onSubmit($formValues) {
  59.         // this what you want to do if everything is all great with your server side validation and you finish everything server side.
  60.         // you can execute javascript, for success or failure, display a page, or even errors.
  61.         $response = array('successPageHtml' => '<h2>Hello World!</h2><p>Thanks for trying out the demonstration form '.$formValues->demonstrationFormPage->demonstrationFormSection->text1.'.</p><p>Check out our <a href="/demos/">Demos Page</a> to see some more advanced demonstrations');
  62.    
  63.         return $response;
  64.     }
  65.    
  66.     // Process any request to the form
  67.     $demonstrationForm->processRequest(true);
  68. ?>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement