HTML_QuickForm_advmultiselect::setButtonAttributes

HTML_QuickForm_advmultiselect::setButtonAttributes() – Sets the button attributes

Synopsis

require_once 'HTML/QuickForm/advmultiselect.php';

void HTML_QuickForm_advmultiselect::setButtonAttributes ( 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', or 'top', or 'bottom'.

value

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

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' 'movedown' 'movetop' or 'movebottom'

mixed $attributes

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

Throws

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

Note

since version 0.4.0 (2005-06-25)

This function can not be called statically.

Example

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 :

<?php
$ams
->setButtonAttributes('add',    array('value' => 'Add >>',
                                          
'class' => 'inputCommand'
));
$ams->setButtonAttributes('remove', array('value' => '<< Remove',
                                          
'class' => 'inputCommand'
));
?>

by lines that should like :

<?php
$ams
->setButtonAttributes('add',    array('type' => 'image',
                                          
'src'  => '/img/add.png'
));
$ams->setButtonAttributes('remove', array('type' => 'image',
                                          
'src'  => '/img/remove.png'
));
?>