* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_multiple_2.php
* qfams_multiple_2 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/multiple2.png
* screenshot (Image PNG, 595x511 pixels) 11.9 Kb
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsMultiple2');
$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',
);
$car_array = array(
'dodge' => 'Dodge',
'chevy' => 'Chevy',
'bmw' => 'BMW',
'audi' => 'Audi',
'porsche' => 'Porsche',
'kia' => 'Kia',
'subaru' => 'Subaru',
'mazda' => 'Mazda',
'isuzu' => 'Isuzu',
);
// template for a single checkboxes multi-select element shape with live counter
$template1 = '
{label_3}({selected_count}) | |
{selected} |
{all} {none} {toggle} |
';
// template for a dual multi-select element shape with live counter
$template2 = '
{label_2}({unselected_count}) |
| {label_3}({selected_count}) |
{unselected} |
{add} {remove}
{all} {none} {toggle}
{moveup} {movedown}
|
{selected} |
';
$defaults = array();
// first QF ams element
$form->addElement('header', null, 'Advanced Multiple Select: Live Counter - pool1 style ');
$ams1 =& $form->addElement('advmultiselect', 'cars', null, $car_array,
array('size' => 10, 'class' => 'pool1', 'style' => 'width:200px;')
);
$ams1->setLabel(array('Cars:', 'Available', 'Selected'));
$ams1->setButtonAttributes('add', array('name' => 'add1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('remove', array('name' => 'remove1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('all', array('name' => 'all1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('none', array('name' => 'none1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('toggle', array('name' => 'toggle1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('moveup', array('name' => 'moveup1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('movedown', array('name' => 'movedown1', 'class' => 'inputCommand'));
if (isset($_POST['multiselect1'])) {
$ams1->setElementTemplate($template2);
} else {
$ams1->setElementTemplate($template1);
}
if (isset($_POST['cars'])) {
$defaults = array('cars' => $_POST['cars']);
}
// second QF ams element
$form->addElement('header', null, 'Advanced Multiple Select: Live Counter - pool2 style ');
$ams2 =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array,
array('size' => 5, 'class' => 'pool2', 'style' => 'width:300px;')
);
$ams2->setLabel(array('Fruit:', 'Available', 'Selected'));
$ams2->setButtonAttributes('add', array('name' => 'add2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('remove', array('name' => 'remove2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('all', array('name' => 'all2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('none', array('name' => 'none2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('toggle', array('name' => 'toggle2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('moveup', array('name' => 'moveup2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('movedown', array('name' => 'movedown2', 'class' => 'inputCommand'));
if (isset($_POST['multiselect2'])) {
$ams2->setElementTemplate($template2);
} else {
$ams2->setElementTemplate($template1);
}
if (isset($_POST['fruit'])) {
$defaults = array_merge($defaults, array('fruit' => $_POST['fruit']));
}
$buttons[] =& $form->createElement('submit', null, 'Submit');
$buttons[] =& $form->createElement('reset', null, 'Reset');
$buttons[] =& $form->createElement('checkbox', 'multiselect1', null,
'cars list dual select');
$buttons[] =& $form->createElement('checkbox', 'multiselect2', null,
'fruit list dual select');
$form->addGroup($buttons, null, ' ');
if (count($defaults) > 0) {
$form->setDefaults($defaults);
}
?>
HTML_QuickForm::advMultiSelect multiple example 2
getElementJs(false); ?>
validate()) {
$clean = $form->getSubmitValues();
echo '';
print_r($clean);
echo '
';
}
$form->display();
?>