HTML_QuickForm_advmultiselect::setPersistantOptions

HTML_QuickForm_advmultiselect::setPersistantOptions() – Sets which items should be persistant

Synopsis

require_once 'HTML/QuickForm/advmultiselect.php';

mixed HTML_QuickForm_advmultiselect::setPersistantOptions ( mixed $optionValues , boolean $persistant = true )

Description

Sets which items should have the disabled attribute to keep it persistant

Parameter

mixed $optionValues

Options (key-values) that should be persistant

boolean $persistant

(optional) TRUE if persistant, FALSE otherwise

Throws

Possible PEAR_Error values
Error message Reason Solution
Argument 1 of HTML_QuickForm_advmultiselect::setPersistantOptions is not a valid array Tried to give array or comma delimited string of selected values Check the $optionValues argument data type and content
Argument 2 of HTML_QuickForm_advmultiselect::setPersistantOptions is not a boolean Tried to give a TRUE or FALSE value Check the $persistant argument data type

Note

since version 1.5.0 (2009-02-15)

This function can not be called statically.

Example

<?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',
    
'tangerine' =>  'Tangerine'
);

$ams =& $form->createElement('advmultiselect''fruit'nullnull,
                             array(
'class' => 'pool''style' => 'width:200px;')
);
$ams->setLabel(array('Fruit:''Available''Selected'));

$ams->setButtonAttributes('add'       'class=inputCommand');
$ams->setButtonAttributes('remove'    'class=inputCommand');
$ams->setButtonAttributes('all'       'class=inputCommand');
$ams->setButtonAttributes('none'      'class=inputCommand');
$ams->setButtonAttributes('toggle'    'class=inputCommand');
$ams->setButtonAttributes('moveup'    'class=inputCommand');
$ams->setButtonAttributes('movedown'  'class=inputCommand');
$ams->setButtonAttributes('movetop'   'class=inputCommand');
$ams->setButtonAttributes('movebottom''class=inputCommand');

$templateDual '
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th>&nbsp;</th><th>{label_3}</th></tr><!-- END label_3 -->
<tr>
  <td>{unselected}</td>
  <td align="center">
    {add}<br />{remove}<br /><br />
    {all}<br />{none}<br />{toggle}<br /><br />
    {moveup}<br />{movedown}<br />{movetop}<br />{movebottom}
  </td>
  <td>{selected}</td>
</tr>
</table>
'
;

$ams->load($fruit_array'pear');

$ams->setPersistantOptions(array('pear''tangerine'));

$ams->setElementTemplate($templateDual);

$form->addElement($ams);

$buttons[] =& $form->createElement('submit'null'Submit');
$buttons[] =& $form->createElement('reset',  null'Reset');
$form->addGroup($buttonsnull'&nbsp;');
?>
<!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 persistant options example</title>
<style type="text/css">
<!--
body {
  background-color: #FFF;
  font-family: Verdana, Arial, helvetica;
  font-size: 10pt;
}

table.pool {
  border: 0;
  background-color: #787878;
}
table.pool td {
  padding-left: 1em;
}
table.pool th {
  font-size: 80%;
  font-style: italic;
  text-align: center;
}
table.pool select {
  color: #242424;
  background-color: #eee;
}

.inputCommand {
  width: 120px;
}
<?php echo $ams->getElementCss(); ?>
 -->
</style>
<?php echo $ams->getElementJs(falsetrue); ?>
</head>
<body>
<?php
if ($form->validate()) {
    
$clean $form->getSubmitValues();

    
var_dump($clean);

    
// if apple fruit is selected, then pear may be remove from next selection
    
if (in_array('apple'$clean['fruit'])) {
        
$ams->setPersistantOptions('pear'false);
    } else {
        
$ams->setPersistantOptions('pear'true);
        
$selection $ams->getSelected();
        if (!
in_array('pear'$selection)) {
            
array_push($selection'pear');
            
$ams->setSelected($selection);
        }
    }
}
$form->display();
?>
</body>
</html>
Returns list of persistant options (Previous) Buttons (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.