HTMLForm
[ class tree: HTMLForm ] [ index: HTMLForm ] [ all elements ]

example

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
  2.  
  3. <html>
  4.  
  5.     <head>
  6.  
  7.         <title>PHP HTML Form Processor Class - Contact Form</title>
  8.  
  9.         <style type="text/css"> body {font-family: tahoma, arial, verdana, sans; font-size: 12px; } </style>
  10.  
  11.     </head>
  12.  
  13.     <body>
  14.     
  15.     <p><strong>Quick tip: </strong>You can send all error messages to a single error block if you want!</p>
  16.  
  17.     <?php
  18.  
  19.         // require the htmlform class
  20.                 require '../class.htmlform.php';
  21.  
  22.         // instantiate the class
  23.                 $form new HTMLForm('form''post');
  24.         
  25.         // add a label to the 'name' control - used in the template file as {controls.label_name}
  26.                 $form->add('label''label_name''name''Your name:');
  27.  
  28.         // add a text control named "name" - used in the template file as {controls.name}
  29.                 $obj $form->add('text''name');
  30.         
  31.         // set the field as mandatory
  32.                 $obj->setRule(array('mandatory' => array('e1''The above field is required!')));
  33.  
  34.         // add a label to the 'email' control - used in the template file as {controls.label_email}
  35.                 $form->add('label''label_email''name''Your email address:');
  36.  
  37.         // add a text control named "email" - used in the template file as {controls.email}
  38.                 $obj $form->add('text''email');
  39.  
  40.         // set the field as mandatory
  41.         // also require a valid email address to be entered
  42.                 $obj->setRule(array('mandatory' => array('e2''The above field is required!')'email' => array('e2''Address seems to be invalid!')));
  43.  
  44.         // add a label to the 'message' control - used in the template file as {controls.label_message}
  45.                 $form->add('label''label_message''message''Message:');
  46.  
  47.         // add a text control named "message" - used in the template file as {controls.message}
  48.                 $obj $form->add('textarea''message'''array('style' => 'width:200px;height:100px'));
  49.  
  50.         // set the field as mandatory
  51.                 $obj->setRule(array('mandatory' => array('e3''The above field is required!')));
  52.         
  53.         $form->add('submit''submit''Submit');
  54.  
  55.         // validate the form
  56.                 if ($form->validate()) {
  57.         
  58.             // code if form is valid
  59.                         print_r('Form is valid. Do your thing (write to db, send emails, whatever) and redirect.');
  60.  
  61.             die();
  62.             
  63.         }
  64.         
  65.         // display the form with the specified template
  66.                 $form->render('forms/contactform.xtpl');
  67.  
  68.         // IF YOU DO NOT NEED ANY SPECIAL FORMATTINGS IN YOUR FORM YOU CAN ALSO CALL THE RENDER METHOD WITHOUT SPECIFYING A TEMPLATE NAME
  69.         // AND THUS LETTING THE SCRIPT TO AUTOMATICALLY GENERATE OUTPUT AND SAVING YOU OF EXTRA WORK PUT INTO DESIGNING THE FORM'S LAYOUT
  70.         // COMMENT THE LINE ABOVE AND UNCOMMENT THE ONE BELOW TO SEE IT IN ACTION
  71.  
  72.         //$form->render();
  73.  
  74.     
  75.     ?>
  76.  
  77.     </body>
  78.  
  79. </html>

Documentation generated on Mon, 22 Sep 2008 11:03:11 +0300 by phpDocumentor 1.3.0RC6