* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_custom_5.php
* qfams_custom_5 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/custom5.png
* screenshot (Image PNG, 609x318 pixels) 9.94 Kb
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsCustom5');
$form->removeAttribute('name'); // XHTML compliance
// same as default element template but wihtout the label (in first td cell)
$withoutLabel = <<<_HTML
|
{error} {element}
|
_HTML;
// more XHTML compliant
// replace default element template with label, because submit button have no label
$renderer =& $form->defaultRenderer();
$renderer->setElementTemplate($withoutLabel, 'validate');
$fruit_array = array(
'apple' => 'Apple',
'orange' => 'Orange',
'pear' => 'Pear',
'banana' => 'Banana',
'cherry' => 'Cherry',
'kiwi' => 'Kiwi',
'lemon' => 'Lemon',
'lime' => 'Lime',
'tangerine' => 'Tangerine',
);
// decides either both select list will have their elements be arranged or not
if (isset($_POST['autoArrange'])) {
if ($_POST['autoArrange'] == 'A') {
$sort = SORT_ASC;
} elseif ($_POST['autoArrange'] == 'D') {
$sort = SORT_DESC;
} else {
$sort = false;
}
} else {
$sort = false;
}
// rendering with QF renderer engine and template system
$form->addElement('header', null,
'For demo purpose only: must be validate to be active');
$arrange[] =& $form->createElement('radio', null, null, 'Auto arrange asc.', 'A');
$arrange[] =& $form->createElement('radio', null, null, 'Auto arrange desc.', 'D');
$arrange[] =& $form->createElement('radio', null, null, 'No auto arrange', 'N');
$form->addGroup($arrange, 'autoArrange', 'Sort list:');
$form->setDefaults(array('autoArrange' => 'N'));
$form->addElement('submit', 'validate', 'Validate');
$form->addElement('header', null, 'Advanced Multiple Select: custom layout ');
$ams =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array,
array('class' => 'pool', 'style' => 'width:200px;'),
$sort
);
$ams->setLabel(array('Fruit:', 'Available', 'Selected'));
$ams->setButtonAttributes('add' , 'class=inputCommand');
$ams->setButtonAttributes('remove' , 'class=inputCommand');
$ams->setButtonAttributes('moveup' , 'class=inputCommand');
$ams->setButtonAttributes('movedown', 'class=inputCommand');
// template for a dual multi-select element shape
$template = '
{label_2} |
| {label_3} |
{unselected} |
{add} {remove}
{moveup} {movedown}
|
{selected} |
';
$ams->setElementTemplate($template);
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// fruit default values already selected without any end-user actions
$form->setDefaults(array('fruit' => array('kiwi','lime')));
} elseif (isset($_POST['fruit'])) {
// fruit end-user selection
$form->setDefaults(array('fruit' => $_POST['fruit']));
}
$buttons[] =& $form->createElement('submit', null, 'Submit');
$buttons[] =& $form->createElement('reset', null, 'Reset');
$form->addGroup($buttons, null, ' ');
?>
HTML_QuickForm::advMultiSelect custom example 5
getElementJs(false); ?>
validate()) {
$clean = $form->getSubmitValues();
echo '';
print_r($clean);
echo '
';
}
$form->display();
?>