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

Source for file qfams_template_1.php

Documentation is available at qfams_template_1.php

  1. <?php
  2. /**
  3.  * Custom advMultiSelect HTML_QuickForm element
  4.  * embedded into a Sigma template and using the QF dynamic renderer.
  5.  *
  6.  * @version    $Id: qfams_template_1.php,v 1.4 2008/04/26 17:26:26 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_template_1.php
  12.  *              qfams_template_1 source code
  13.  * @link       http://www.laurent-laville.org/img/qfams/screenshot/template1.png
  14.  *              screenshot (Image PNG, 665x376 pixels) 23.3 Kb
  15.  */
  16.  
  17. require_once 'HTML/Template/Sigma.php';
  18. require_once 'HTML/QuickForm.php';
  19. require_once 'HTML/QuickForm/Renderer/ITDynamic.php';
  20. require_once 'HTML/QuickForm/advmultiselect.php';
  21.  
  22. $form = new HTML_QuickForm('amsTemplate1');
  23. $form->removeAttribute('name');        // XHTML compliance
  24.  
  25. $fruit_array = array(
  26.     'apple'     =>  'Apple',
  27.     'orange'    =>  'Orange',
  28.     'pear'      =>  'Pear',
  29.     'banana'    =>  'Banana',
  30.     'cherry'    =>  'Cherry',
  31.     'kiwi'      =>  'Kiwi',
  32.     'lemon'     =>  'Lemon',
  33.     'lime'      =>  'Lime',
  34.     'tangerine' =>  'Tangerine',
  35. );
  36.  
  37. // rendering with css selectors and API selLabel(), setButtonAttributes()
  38. $form->addElement('header'null'Advanced Multiple Select: custom layout ');
  39.  
  40. $form->addElement('text''name''Name:'array('size' => 40'maxlength' => 80));
  41.  
  42. $ams =$form->addElement('advmultiselect''fruit'null$fruit_array,
  43.                            array('size' => 15,
  44.                                  'class' => 'pool''style' => 'width:150px;'
  45.                                 )
  46. );
  47. $ams->setLabel(array('Fruit:''Available''Selected'));
  48. $ams->setButtonAttributes('add',    array('value' => 'Add >>',
  49.                                            'class' => 'inputCommand'
  50. ));
  51. $ams->setButtonAttributes('remove'array('value' => '<< Remove',
  52.                                            'class' => 'inputCommand'
  53. ));
  54. $template '
  55. <table{class}>
  56. <!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
  57. <!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
  58. <tr>
  59.   <td valign="top">{unselected}</td>
  60.   <td align="center">{add}{remove}</td>
  61.   <td valign="top">{selected}</td>
  62. </tr>
  63. </table>
  64. ';
  65. $ams->setElementTemplate($template);
  66.  
  67. if (isset($_POST['fruit'])) {
  68.     $form->setDefaults(array('fruit' => $_POST['fruit']));
  69. }
  70.  
  71. $form->addElement('submit''send''Send'array('class' => 'inputCommand'));
  72.  
  73. $form->addRule('name''Your name is required''required');
  74. $form->addGroupRule('fruit''At least one fruit is required''required'null1);
  75.  
  76. $form->applyFilter('__ALL__''trim');
  77. $form->applyFilter('__ALL__''strip_tags');
  78.  
  79. $valid $form->validate();
  80.  
  81. $tpl = new HTML_Template_Sigma('.');
  82. $tpl->loadTemplateFile('itdynamic.html');
  83. $tpl->setVariable('ams_javascript'$ams->getElementJs(false));
  84.  
  85. $renderer = new HTML_QuickForm_Renderer_ITDynamic($tpl);
  86.  
  87. $form->accept($renderer);
  88.  
  89. if ($valid{
  90.     $clean $form->getSubmitValues();
  91.  
  92.     $msg sprintf("<p>Welcome <b>%s</b> you've selected these fruits:<br />%s</p>",
  93.            $clean['name']implode(', '$clean['fruit']));
  94.  
  95.     $tpl->setVariable('message_form_validate'$msg);
  96. }
  97. $tpl->show();
  98. ?>

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