PEAR logo

HTML_QuickForm_advmultiselect : The Definitive Guide



Name

HTML_QuickForm_advmultiselect::setElementTemplate - Sets element template

Synopsis

      require_once 'HTML/QuickForm/advmultiselect.php';
     
void HTML_QuickForm_advmultiselect::setElementTemplate( $html);
string $html;

Description

It is so easy to re-arrange select boxes, headers and buttons position. The template is a bit of html code with reserved placeholders words. They are:

stylesheet

The CSS delimited by the style tags required only for the single multi-select with checkboxes shape. Not included in the default template. You can use instead, the getElementCss method.

javascript

The JavaScript delimited by the script tags required to manage item of both multi-select boxes. If it is not included, you can use instead, the getElementJs method.

class

A CSS class identifier in one of your stylesheets that is the default table layout. Default values are:

          
<table border="0" cellpadding="10" cellspacing="0">
          
         
label_2

The unselected list header

label_3

The selected list header

unselected

The unselected list.

selected

The selected list.

add

The add button to swap one (or more) item from the unselected to the selected list.

remove

The remove button to swap one (or more) item back from the selected to the unselected list.

moveup

The button to move one item of the selected list to the top.

movedown

The button to move one item of the selected list to the bottom.

Parameter

string $html

The HTML surrounding select boxes and buttons

Throws

throws no exceptions thrown

Note

since 0.4.0

This function can not be called statically.

Example

In this partial example, the fruit list select boxes are set to vertical alignement with images for the 'add' and 'remove' buttons. Default presentation are horizontal alignment with input text buttons in the middle side.

  1. <?php
  2. require_once 'HTML/QuickForm.php';
  3. require_once 'HTML/QuickForm/advmultiselect.php';
  4.  
  5. $form = new HTML_QuickForm('ams');
  6. $form->removeAttribute('name');        // XHTML compliance
  7.  
  8. $fruit_array = array(
  9.     'apple'     =>  'Apple',
  10.     'orange'    =>  'Orange',
  11.     'pear'      =>  'Pear',
  12.     'banana'    =>  'Banana',
  13.     'cherry'    =>  'Cherry',
  14.     'kiwi'      =>  'Kiwi',
  15.     'lemon'     =>  'Lemon',
  16.     'lime'      =>  'Lime',
  17.     'tangerine' =>  'Tangerine',
  18. );
  19.  
  20. $ams =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array);
  21. $ams->setLabel(array('Fruit:', 'Available', 'Selected'));
  22. $ams->setButtonAttributes('add',    array('type' => 'image', 'src' => '/img/down.png'));
  23. $ams->setButtonAttributes('remove', array('type' => 'image', 'src' => '/img/up.png'));
  24.  
  25. // vertical select box with image buttons as selector
  26. $template = '
  27. <table{class}>
  28. <!-- BEGIN label_2 --><tr><th align="center">{label_2}</th></tr><!-- END label_2 -->
  29. <tr>
  30.   <td>{unselected}</td>
  31. </tr>
  32. <tr>
  33.   <td align="center">{add}{remove}</td>
  34. </tr>
  35. <tr>
  36.   <td>{selected}</td>
  37. </tr>
  38. <!-- BEGIN label_3 --><tr><th align="center">{label_3}</th></tr><!-- END label_3 -->
  39. </table>';
  40. $ams->setElementTemplate($template);
  41.  
  42. // ....
  43. ?>
HTML_QuickForm_advmultiselect : The Definitive Guide v 1.4.0 : 9 Juin 2007