* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_custom_3.php
* qfams_custom_3 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/custom3.png
* screenshot (Image PNG, 374x275 pixels) 4.96 Kb
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsCustom3');
$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, 'send');
$fruit_array = array(
'apple' => 'Apple',
'orange' => 'Orange',
'pear' => array('Pear', array('disabled' => 'disabled')),
'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, null,
array('class' => 'pool')
);
foreach ($fruit_array as $key => $data) {
if (!is_array($data)) {
$data = array($data);
}
$attr = isset($data[1]) ? $data[1] : null;
$ams->addOption($data[0], $key, $attr);
}
$ams->setLabel(array('Fruit:', 'Available', 'Selected'));
$ams->setButtonAttributes('add', array('value' => 'Add >>',
'class' => 'inputCommand'
));
$ams->setButtonAttributes('remove', array('value' => '<< Remove',
'class' => 'inputCommand'
));
$template = '
{label_2} |
{label_3} |
{unselected} |
{selected} |
{add} |
{remove} |
';
$ams->setElementTemplate($template);
if (isset($_POST['fruit'])) {
$form->setDefaults(array('fruit' => $_POST['fruit']));
}
$form->addElement('submit', 'send', 'Send');
?>
HTML_QuickForm::advMultiSelect custom example 3
getElementJs(false); ?>
validate()) {
$clean = $form->getSubmitValues();
echo '';
print_r($clean);
echo '
';
}
$form->display();
?>