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

Custom example 2: source code

  1. <?php
  2. /**
  3.  * Custom advMultiSelect HTML_QuickForm element
  4.  * using images for 'add' and 'remove' buttons.
  5.  *
  6.  * The template allows to add label as headers of dual select box
  7.  * and moves the buttons between the two select box (up and down).
  8.  *
  9.  * @version    $Id: qfams_custom_2.php,v 1.5 2009/01/28 22:24:43 farell Exp $
  10.  * @author     Laurent Laville <pear@laurent-laville.org>
  11.  * @package    HTML_QuickForm_advmultiselect
  12.  * @subpackage Examples
  13.  * @access     public
  14.  * @example    examples/qfams_custom_2.php
  15.  *              qfams_custom_2 source code
  16.  * @link       http://www.laurent-laville.org/img/qfams/screenshot/custom2.png
  17.  *              screenshot (Image PNG, 374x302 pixels) 5.80 Kb
  18.  */
  19.  
  20. require_once 'HTML/QuickForm.php';
  21. require_once 'HTML/QuickForm/advmultiselect.php';
  22.  
  23. $form = new HTML_QuickForm('amsCustom2');
  24. $form->removeAttribute('name');        // XHTML compliance
  25.  
  26. // same as default element template but wihtout the label (in first td cell)
  27. $withoutLabel = <<<_HTML
  28. <tr valign="top">
  29.     <td align="right">
  30.         &nbsp;
  31.     </td>
  32.     <td align="left">
  33.         <!-- BEGIN error --><span style="color: #ff0000;">{error}</span><br /><!-- END error -->{element}
  34.     </td>
  35. </tr>
  36. _HTML;
  37.  
  38. // more XHTML compliant
  39. // replace default element template with label, because submit button have no label
  40. $renderer =$form->defaultRenderer();
  41. $renderer->setElementTemplate($withoutLabel'send');
  42.  
  43. $fruit_array = array(
  44.     'apple'     =>  'Apple',
  45.     'orange'    =>  'Orange',
  46.     'pear'      =>  'Pear',
  47.     'banana'    =>  'Banana',
  48.     'cherry'    =>  'Cherry',
  49.     'kiwi'      =>  'Kiwi',
  50.     'lemon'     =>  'Lemon',
  51.     'lime'      =>  'Lime',
  52.     'tangerine' =>  'Tangerine',
  53. );
  54.  
  55. // rendering with QF renderer engine and template system
  56. $form->addElement('header'null'Advanced Multiple Select: custom layout ');
  57.  
  58. $ams =$form->addElement('advmultiselect''fruit'null$fruit_array,
  59.                            array('size' => 5,
  60.                                  'class' => 'pool''style' => 'width:300px;'
  61.                                 )
  62. );
  63. $ams->setLabel(array('Fruit:''Available''Selected'));
  64. $ams->setButtonAttributes('add',    array('type' => 'image''src' => '/img/qfams/down.png'));
  65. $ams->setButtonAttributes('remove'array('type' => 'image''src' => '/img/qfams/up.png'));
  66.  
  67. // vertical select box with image buttons as selector
  68. $template '
  69. <table{class}>
  70. <!-- BEGIN label_2 --><tr><th align="center">{label_2}</th></tr><!-- END label_2 -->
  71. <tr>
  72.   <td>{unselected}</td>
  73. </tr>
  74. <tr>
  75.   <td align="center">{add}{remove}</td>
  76. </tr>
  77. <tr>
  78.   <td>{selected}</td>
  79. </tr>
  80. <!-- BEGIN label_3 --><tr><th align="center">{label_3}</th></tr><!-- END label_3 -->
  81. </table>';
  82. $ams->setElementTemplate($template);
  83.  
  84. $form->addElement('submit''send''Send');
  85. ?>
  86. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  87.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  88. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  89. <head>
  90. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  91. <title>HTML_QuickForm::advMultiSelect custom example 2</title>
  92. <style type="text/css">
  93. <!--
  94. body {
  95.   background-color: #FFF;
  96.   font-family: Verdana, Arial, helvetica;
  97.   font-size: 10pt;
  98. }
  99.  
  100. table.pool {
  101.   border: 0;
  102. }
  103. table.pool th {
  104.   font-size: 80%;
  105.   font-style: italic;
  106.   text-align: center;
  107. }
  108. table.pool select {
  109.   background-color: lightyellow;
  110. }
  111.  -->
  112. </style>
  113. <?php echo $ams->getElementJs(false)?>
  114. </head>
  115. <body>
  116. <?php
  117. if ($form->validate()) {
  118.     $clean $form->getSubmitValues();
  119.  
  120.     echo '<pre>';
  121.     print_r($clean);
  122.     echo '</pre>';
  123. }
  124. $form->display();
  125. ?>
  126. </body>
  127. </html>

Documentation generated on Mon, 11 Mar 2019 15:30:49 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.