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

Multiple example 1: source code

  1. <?php
  2. /**
  3.  * Mixed advMultiSelect HTML_QuickForm elements.
  4.  * Two widgets on the same page/form with each its own javascript function
  5.  *
  6.  * @version    $Id: qfams_multiple_1.php,v 1.4 2008/04/26 17:25:59 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_multiple_1.php
  12.  *              qfams_multiple_1 source code
  13.  * @link       http://www.laurent-laville.org/img/qfams/screenshot/multiple1.png
  14.  *              screenshot (Image PNG, 566x392 pixels) 8.82 Kb
  15.  */
  16.  
  17. require_once 'HTML/QuickForm.php';
  18. require_once 'HTML/QuickForm/advmultiselect.php';
  19.  
  20. $form = new HTML_QuickForm('amsMultiple1');
  21. $form->removeAttribute('name');        // XHTML compliance
  22.  
  23. // same as default element template but wihtout the label (in first td cell)
  24. $withoutLabel = <<<_HTML
  25. <tr valign="top">
  26.     <td align="right">
  27.         &nbsp;
  28.     </td>
  29.     <td align="left">
  30.         <!-- BEGIN error --><span style="color: #ff0000;">{error}</span><br /><!-- END error -->{element}
  31.     </td>
  32. </tr>
  33. _HTML;
  34.  
  35. // more XHTML compliant
  36. // replace default element template with label, because submit button have no label
  37. $renderer =$form->defaultRenderer();
  38. $renderer->setElementTemplate($withoutLabel'send');
  39.  
  40. $fruit_array = array(
  41.     'apple'     =>  'Apple',
  42.     'orange'    =>  'Orange',
  43.     'pear'      =>  'Pear',
  44.     'banana'    =>  'Banana',
  45.     'cherry'    =>  'Cherry',
  46.     'kiwi'      =>  'Kiwi',
  47.     'lemon'     =>  'Lemon',
  48.     'lime'      =>  'Lime',
  49.     'tangerine' =>  'Tangerine',
  50. );
  51.  
  52. $car_array = array(
  53.     'dodge'     =>  'Dodge',
  54.     'chevy'     =>  'Chevy',
  55.     'bmw'       =>  'BMW',
  56.     'audi'      =>  'Audi',
  57.     'porsche'   =>  'Porsche',
  58.     'kia'       =>  'Kia',
  59.     'subaru'    =>  'Subaru',
  60.     'mazda'     =>  'Mazda',
  61.     'isuzu'     =>  'Isuzu',
  62. );
  63.  
  64. // rendering with all default options
  65. $form->addElement('header'null'Advanced Multiple Select: default layout ');
  66.  
  67. $ams1 =$form->addElement('advmultiselect''cars''Cars:'$car_array);
  68.  
  69. if (isset($_POST['cars'])) {
  70.     $form->setDefaults(array('cars' => $_POST['cars']));
  71. }
  72.  
  73. // rendering with css selectors and API selLabel(), setButtonAttributes()
  74. $form->addElement('header'null'Advanced Multiple Select: custom layout ');
  75.  
  76. $ams2 =$form->addElement('advmultiselect''fruit'null$fruit_array,
  77.                            array('size' => 5,
  78.                                  'class' => 'pool''style' => 'width:200px;'
  79.                                 )
  80. );
  81. $ams2->setJsElement('fruit_');
  82. $ams2->setLabel(array('Fruit:''Available''Selected'));
  83. $ams2->setButtonAttributes('add',    array('value' => 'Add''name' => 'add1',
  84.                                            'class' => 'inputCommand'
  85. ));
  86. $ams2->setButtonAttributes('remove'array('value' => 'Remove''name' => 'remove1',
  87.                                            'class' => 'inputCommand'
  88. ));
  89.  
  90. if (isset($_POST['fruit'])) {
  91.     $form->setDefaults(array('fruit' => $_POST['fruit']));
  92. }
  93.  
  94. $form->addElement('submit''send''Send');
  95. ?>
  96. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  97.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  98. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  99. <head>
  100. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  101. <title>HTML_QuickForm::advMultiSelect multiple example 1</title>
  102. <style type="text/css">
  103. <!--
  104. body {
  105.   background-color: #FFF;
  106.   font-family: Verdana, Arial, helvetica;
  107.   font-size: 10pt;
  108. }
  109.  
  110. table.pool {
  111.   border: 0;
  112.   background-color: #339900;
  113.   width:450px;
  114. }
  115. table.pool th {
  116.   font-size: 80%;
  117.   font-style: italic;
  118.   text-align: left;
  119. }
  120. table.pool select {
  121.   color: white;
  122.   background-color: #006600;
  123. }
  124.  
  125. .inputCommand {
  126.     background-color: #d0d0d0;
  127.     border: 1px solid #7B7B88;
  128.     width: 7em;
  129.     margin-bottom: 2px;
  130. }
  131.  -->
  132. </style>
  133. <script type="text/javascript">
  134. //<![CDATA[
  135. <?php
  136. echo $ams1->getElementJs();
  137.  
  138. echo $ams2->getElementJs();
  139. ?>
  140. //]]>
  141. </script>
  142. </head>
  143. <body>
  144. <?php
  145. if ($form->validate()) {
  146.     $clean $form->getSubmitValues();
  147.  
  148.     echo '<pre>';
  149.     print_r($clean);
  150.     echo '</pre>';
  151. }
  152. $form->display();
  153. ?>
  154. </body>
  155. </html>

Documentation generated on Sat, 26 Apr 2008 14:30:08 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.