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

Source for file qfams_custom_3.php

Documentation is available at qfams_custom_3.php

  1. <?php
  2. /**
  3.  * Custom advMultiSelect HTML_QuickForm element
  4.  * loading values with fancy attributes (disabled, ...)
  5.  *
  6.  * @version    $Id: qfams_custom_3.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_custom_3.php
  12.  *              qfams_custom_3 source code
  13.  * @link       http://www.laurent-laville.org/img/qfams/screenshot/custom3.png
  14.  *              screenshot (Image PNG, 374x275 pixels) 4.96 Kb
  15.  */
  16.  
  17. require_once 'HTML/QuickForm.php';
  18. require_once 'HTML/QuickForm/advmultiselect.php';
  19.  
  20. $form = new HTML_QuickForm('amsCustom3');
  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'      =>  array('Pear'array('disabled' => 'disabled')),
  44.     'banana'    =>  'Banana',
  45.     'cherry'    =>  'Cherry',
  46.     'kiwi'      =>  'Kiwi',
  47.     'lemon'     =>  'Lemon',
  48.     'lime'      =>  'Lime',
  49.     'tangerine' =>  'Tangerine',
  50. );
  51.  
  52. // rendering with QF renderer engine and template system
  53. $form->addElement('header'null'Advanced Multiple Select: custom layout ');
  54.  
  55. $ams =$form->addElement('advmultiselect''fruit'nullnull,
  56.                            array('class' => 'pool')
  57. );
  58. foreach ($fruit_array as $key => $data{
  59.     if (!is_array($data)) {
  60.         $data = array($data);
  61.     }
  62.     $attr = isset($data[1]$data[1: null;
  63.     $ams->addOption($data[0]$key$attr);
  64. }
  65.  
  66. $ams->setLabel(array('Fruit:''Available''Selected'));
  67. $ams->setButtonAttributes('add',    array('value' => 'Add >>',
  68.                                            'class' => 'inputCommand'
  69. ));
  70. $ams->setButtonAttributes('remove'array('value' => '<< Remove',
  71.                                            'class' => 'inputCommand'
  72. ));
  73. $template '
  74. <table{class}>
  75. <!-- BEGIN label_2 --><tr><th align="center">{label_2}</th><!-- END label_2 -->
  76. <!-- BEGIN label_3 --><th align="center">{label_3}</th></tr><!-- END label_3 -->
  77. <tr>
  78.   <td>{unselected}</td>
  79.   <td>{selected}</td>
  80. </tr>
  81. <tr>
  82.   <td>{add}</td>
  83.   <td>{remove}</td>
  84. </tr>
  85. </table>';
  86. $ams->setElementTemplate($template);
  87.  
  88. if (isset($_POST['fruit'])) {
  89.     $form->setDefaults(array('fruit' => $_POST['fruit']));
  90. }
  91.  
  92. $form->addElement('submit''send''Send');
  93. ?>
  94. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  95.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  96. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  97. <head>
  98. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  99. <title>HTML_QuickForm::advMultiSelect custom example 3</title>
  100. <style type="text/css">
  101. <!--
  102. body {
  103.   background-color: #FFF;
  104.   font-family: Verdana, Arial, helvetica;
  105.   font-size: 10pt;
  106. }
  107.  
  108. table.pool {
  109.   border: 0;
  110.   background-color: lightyellow;
  111. }
  112. table.pool td {
  113.   padding-left: 1em;
  114. }
  115. table.pool th {
  116.   font-size: 80%;
  117.   font-style: italic;
  118.   text-align: center;
  119. }
  120. table.pool select {
  121.   background-color: lightblue;
  122. }
  123.  
  124. .inputCommand {
  125.     background-color: #d0d0d0;
  126.     border: 1px solid #7B7B88;
  127.     width: 7em;
  128.     margin-bottom: 2px;
  129. }
  130.  -->
  131. </style>
  132. <?php echo $ams->getElementJs(false)?>
  133. </head>
  134. <body>
  135. <?php
  136. if ($form->validate()) {
  137.     $clean $form->getSubmitValues();
  138.  
  139.     echo '<pre>';
  140.     print_r($clean);
  141.     echo '</pre>';
  142. }
  143. $form->display();
  144. ?>
  145. </body>
  146. </html>

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