PEAR logo

HTML_QuickForm_advmultiselect : The Definitive Guide



Chapter 9. Examples

Table of Contents

Basic usage
Extended usage
Advanced selection usage
Sort usage
Combines multiple elements
Template engine usage
Live counter combines with multiple elements

Basic usage

Figure 9.1. Basic usage with default layout

Basic usage with default layout

This example has no particular goals. It should be your first run to show and handle a advmultiselect element that will emulate a multi-select.

Example 9.1. Without any customization

  1. <?php
  2. /**
  3. * Basic advMultiSelect HTML_QuickForm element
  4. * without any customization.
  5. *
  6. * @version    $Id: qfams_basic_1.php,v 1.3 2007/01/05 15:35:33 farell Exp $
  7. * @author     Laurent Laville <pear@laurent-laville.org>
  8. * @package    HTML_QuickForm_advmultiselect
  9. * @subpackage Examples
  10. * @access     public
  11. * @example    examples/qfams_basic_1.php
  12. *             qfams_basic_1 source code
  13. * @link       http://www.laurent-laville.org/img/qfams/screenshot/basic1.png
  14. *             screenshot (Image PNG, 406x247 pixels) 4.95 Kb
  15. */
  16.  
  17. require_once 'HTML/QuickForm.php';
  18. require_once 'HTML/QuickForm/advmultiselect.php';
  19.  
  20. $form = new HTML_QuickForm('amsBasic1');
  21. $form->removeAttribute('name');        // XHTML compliance
  22.  
  23. $car_array = array(
  24.     'dodge'     =>  'Dodge',
  25.     'chevy'     =>  'Chevy',
  26.     'bmw'       =>  'BMW',
  27.     'audi'      =>  'Audi',
  28.     'porsche'   =>  'Porsche',
  29.     'kia'       =>  'Kia',
  30.     'subaru'    =>  'Subaru',
  31.     'mazda'     =>  'Mazda',
  32.     'isuzu'     =>  'Isuzu',
  33. );
  34.  
  35. // rendering with all default options
  36. $form->addElement('header', null, 'Advanced Multiple Select: default layout ');
  37.  
  38. $form->addElement('advmultiselect', 'cars', 'Cars:', $car_array);
  39.  
  40. if (isset($_POST['cars'])) {
  41.     $form->setDefaults(array('cars' => $_POST['cars']));
  42. }
  43.  
  44. $form->addElement('submit', 'send', 'Send');
  45.  
  46. ?>
  47. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  48.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  49. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  50. <head>
  51. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  52. <title>HTML_QuickForm::advMultiSelect basic example 1</title>
  53. <style type="text/css">
  54. <!--
  55. body {
  56.   background-color: #FFF;
  57.   font-family: Verdana, Arial, helvetica;
  58.   font-size: 10pt;
  59. }
  60.  -->
  61. </style>
  62. </head>
  63. <body>
  64. <?php
  65. if ($form->validate()) {
  66.     $clean = $form->getSubmitValues();
  67.  
  68.     echo '<pre>';
  69.     print_r($clean);
  70.     echo '</pre>';
  71. }
  72. $form->display();
  73. ?>
  74. </body>
  75. </html>
HTML_QuickForm_advmultiselect : The Definitive Guide v 1.4.0 : 9 Juin 2007