![]() HTML_QuickForm_advmultiselect : The Definitive Guide |
HTML_QuickForm_advmultiselect::setButtonAttributes
- Sets the button attributes
require_once 'HTML/QuickForm/advmultiselect.php';
void HTML_QuickForm_advmultiselect::setButtonAttributes(
|
$button, | |
$attributes = NULL) ;
|
string | $button; |
mixed | $attributes = NULL; |
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.
$button
Button identifier, either 'add', 'remove', 'all', 'none', 'toggle', 'moveup' or 'movedown'
$attributes
(optional) Either a typical HTML attribute string or an associative array
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 |
In this example, the 'add' and 'remove' buttons have look set by the css class 'inputCommand'.
<?php require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/advmultiselect.php'; $form = new HTML_QuickForm('ams'); $form->removeAttribute('name'); // XHTML compliance $fruit_array = array( 'apple' => 'Apple', 'orange' => 'Orange', 'pear' => 'Pear', 'banana' => 'Banana', 'cherry' => 'Cherry', 'kiwi' => 'Kiwi', 'lemon' => 'Lemon', 'lime' => 'Lime', 'tangerine' => 'Tangerine', ); // rendering with QF renderer engine and template system $form->addElement('header', null, 'Advanced Multiple Select: custom layout '); $ams =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array); $ams->setLabel(array('Fruit:', 'Available', 'Selected')); $ams->setButtonAttributes('add', array('value' => 'Add >>', 'class' => 'inputCommand' )); $ams->setButtonAttributes('remove', array('value' => '<< Remove', 'class' => 'inputCommand' )); $template = ' <table{class}> <!-- BEGIN label_2 --><tr><th align="center">{label_2}</th><!-- END label_2 --> <!-- BEGIN label_3 --><th align="center">{label_3}</th></tr><!-- END label_3 --> <tr> <td>{unselected}</td> <td>{selected}</td> </tr> <tr> <td>{add}</td> <td>{remove}</td> </tr> </table>'; $ams->setElementTemplate($template); if (isset($_POST['fruit'])) { $form->setDefaults(array('fruit' => $_POST['fruit'])); } $form->addElement('submit', 'send', 'Send'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>HTML_QuickForm::advMultiSelect example </title> <style type="text/css"> <!-- body { background-color: #FFF; font-family: Verdana, Arial, helvetica; font-size: 10pt; } .inputCommand { background-color: #d0d0d0; border: 1px solid #7B7B88; width: 7em; margin-bottom: 2px; } // --> </style> <?php echo $ams->getElementJs(false); ?> </head> <body> <?php if ($form->validate()) { $clean = $form->getSubmitValues(); echo '<pre>'; print_r($clean); echo '</pre>'; } $form->display(); ?> </body> </html>
You may also use images rather than standard form input button. Replaces lines :
$ams->setButtonAttributes('add', array('value' => 'Add >>', 'class' => 'inputCommand' )); $ams->setButtonAttributes('remove', array('value' => '<< Remove', 'class' => 'inputCommand' ));
by lines that should like :
$ams->setButtonAttributes('add', array('type' => 'image', 'src' => '/img/add.png' )); $ams->setButtonAttributes('remove', array('type' => 'image', 'src' => '/img/remove.png' ));
HTML_QuickForm_advmultiselect : The Definitive Guide | v 1.3.0 : January 6, 2007 |