PEAR logo

HTML_QuickForm_advmultiselect : The Definitive Guide



Name

HTML_QuickForm_advmultiselect::setButtonAttributes - Sets the button attributes

Synopsis

      require_once 'HTML/QuickForm/advmultiselect.php';
     
void HTML_QuickForm_advmultiselect::setButtonAttributes( $button,
$attributes = NULL);
string $button;
mixed $attributes = NULL;

Description

The basic settings gave standard form input buttons. You may change the look with some CSS if you set the class attribute in the $attributes hash (second parameter). See example section.

Only five attributes may be set, they are:

name

The form input button name. Default are: 'add', or 'remove', or, 'all', or 'none', or 'toggle', or 'up', or 'down'.

value

The form input button text. Default are ' >> ', or ' << ', or ' Select All ', or ' Select None ', or ' Toggle Selection ', or ' Up ', or ' Down '.

type

The form input button kind. Default is 'button' (Can be either 'button' or 'image').

class

A CSS class identifier in one of your stylesheets.

src

URL of the image file used.

Parameter

string $button

Button identifier, either 'add', 'remove', 'all', 'none', 'toggle', 'moveup' or 'movedown'

mixed $attributes

(optional) Either a typical HTML attribute string or an associative array

Throws

Table 8.1. Possible PEAR_Error values

Error message Reason Solution
Argument 1 of advmultiselect::setButtonAttributes is not a string Tried to give a button identifier of unknown type Check the $button argument data type
Argument 1 of advmultiselect::setButtonAttributes has unexpected value Tried to give a button identifier of unknown value Check the $button argument data range

Note

since 0.4.0

This function can not be called statically.

Example

In this example, the 'add' and 'remove' buttons have look set by the css class 'inputCommand'.

  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. // rendering with QF renderer engine and template system
  21. $form->addElement('header', null, 'Advanced Multiple Select: custom layout ');
  22.  
  23. $ams =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array);
  24.  
  25. $ams->setLabel(array('Fruit:', 'Available', 'Selected'));
  26. $ams->setButtonAttributes('add',    array('value' => 'Add >>',
  27.                                           'class' => 'inputCommand'
  28. ));
  29. $ams->setButtonAttributes('remove', array('value' => '<< Remove',
  30.                                           'class' => 'inputCommand'
  31. ));
  32. $template = '
  33. <table{class}>
  34. <!-- BEGIN label_2 --><tr><th align="center">{label_2}</th><!-- END label_2 -->
  35. <!-- BEGIN label_3 --><th align="center">{label_3}</th></tr><!-- END label_3 -->
  36. <tr>
  37.   <td>{unselected}</td>
  38.   <td>{selected}</td>
  39. </tr>
  40. <tr>
  41.   <td>{add}</td>
  42.   <td>{remove}</td>
  43. </tr>
  44. </table>';
  45. $ams->setElementTemplate($template);
  46.  
  47. if (isset($_POST['fruit'])) {
  48.     $form->setDefaults(array('fruit' => $_POST['fruit']));
  49. }
  50.  
  51. $form->addElement('submit', 'send', 'Send');
  52. ?>
  53. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  54.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  55. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  56. <head>
  57. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  58. <title>HTML_QuickForm::advMultiSelect example </title>
  59. <style type="text/css">
  60. <!--
  61. body {
  62.   background-color: #FFF;
  63.   font-family: Verdana, Arial, helvetica;
  64.   font-size: 10pt;
  65. }
  66.  
  67. .inputCommand {
  68.     background-color: #d0d0d0;
  69.     border: 1px solid #7B7B88;
  70.     width: 7em;
  71.     margin-bottom: 2px;
  72. }
  73. // -->
  74. </style>
  75. <?php echo $ams->getElementJs(false); ?>
  76. </head>
  77. <body>
  78. <?php
  79. if ($form->validate()) {
  80.     $clean = $form->getSubmitValues();
  81.  
  82.     echo '<pre>';
  83.     print_r($clean);
  84.     echo '</pre>';
  85. }
  86. $form->display();
  87. ?>
  88. </body>
  89. </html>

You may also use images rather than standard form input button. Replaces lines :

  1. $ams->setButtonAttributes('add',    array('value' => 'Add >>',
  2.                                           'class' => 'inputCommand'
  3. ));
  4. $ams->setButtonAttributes('remove', array('value' => '<< Remove',
  5.                                           'class' => 'inputCommand'
  6. ));

by lines that should like :

  1. $ams->setButtonAttributes('add',    array('type' => 'image',
  2.                                           'src'  => '/img/add.png'
  3. ));
  4. $ams->setButtonAttributes('remove', array('type' => 'image',
  5.                                           'src'  => '/img/remove.png'
  6. ));
HTML_QuickForm_advmultiselect : The Definitive Guide v 1.4.0 : 9 Juin 2007