PEAR logo

HTML_QuickForm_advmultiselect : The Definitive Guide



Name

HTML_QuickForm_advmultiselect::getElementCss - Gets default element stylesheet for a single multi-select shape render

Synopsis

      require_once 'HTML/QuickForm/advmultiselect.php';
     
string HTML_QuickForm_advmultiselect::getElementCss( $raw = TRUE);
boolean $raw = TRUE;

Description

If your browser does not support javascript, or for any reasons you have choosen to disable it, then your only possibility is to use the single checkboxes multi-select shape of HTML_QuickForm_advmultiselect element.

You get a more or less decent result with just the basic settings, but it is also highly configurable, so you can almost get what you want.

The basic settings can be applied with just the placeholder {stylesheet} into your template element. It can also be applied with getElementCss method. If you does not have existing style tags in your html page, you must call the method with FALSE argument. Default behavior returns only the raw css data without style tags. Useful when using with template engine.

Parameter

boolean $raw

(optional) html output with style tags or just raw data

Throws

throws no exceptions thrown

Note

since 0.4.0

This function can not be called statically.

Example

  1. <?php
  2. require_once 'HTML/QuickForm.php';
  3. require_once 'HTML/QuickForm/advmultiselect.php';
  4.  
  5. $form = new HTML_QuickForm('ams');
  6. $form->removeAttribute('name');        // XHTML compliance
  7.  
  8. $fruit_array = array(
  9.     'apple'     =>  'Apple',
  10.     'orange'    =>  'Orange',
  11.     'pear'      =>  'Pear',
  12.     'banana'    =>  'Banana',
  13.     'cherry'    =>  'Cherry',
  14.     'kiwi'      =>  'Kiwi',
  15.     'lemon'     =>  'Lemon',
  16.     'lime'      =>  'Lime',
  17.     'tangerine' =>  'Tangerine'
  18. );
  19.  
  20. // rendering with QF renderer engine and template system
  21. $form->addElement('header', null, 'Advanced Multiple Select: custom layout ');
  22.  
  23. $ams =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array);
  24. $ams->setLabel(array('Fruit:', 'Available', 'Selected'));
  25.  
  26. // template for a single checkboxes multi-select element shape
  27. $template = '
  28. <table{class}>
  29. <!-- BEGIN label_3 --><tr><th>{label_3}</th></tr><!-- END label_3 -->
  30. <tr>
  31.   <td>{selected}</td>
  32. </tr>
  33. </table>
  34. ';
  35. $ams->setElementTemplate($template);
  36.  
  37. if ($_SERVER['REQUEST_METHOD'] == 'GET') {
  38.     // fruit default values already selected without any end-user actions
  39.     $form->setDefaults(array('fruit' => array('kiwi','lime')));
  40.  
  41. } elseif (isset($_POST['fruit'])) {
  42.     // fruit end-user selection
  43.     $form->setDefaults(array('fruit' => $_POST['fruit']));
  44. }
  45.  
  46. $buttons[] =& $form->createElement('submit', null, 'Submit');
  47. $buttons[] =& $form->createElement('reset', null, 'Reset');
  48. $form->addGroup($buttons);
  49. ?>
  50. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  51.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  52. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  53. <head>
  54. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  55. <title>HTML_QuickForm::advMultiSelect custom example 4b</title>
  56. <style type="text/css">
  57. <!--
  58. body {
  59.   background-color: #FFF;
  60.   font-family: Verdana, Arial, helvetica;
  61.   font-size: 10pt;
  62. }
  63. <?php echo $ams->getElementCss(); ?>
  64. // -->
  65. </style>
  66. </head>
  67. <body>
  68. <?php
  69. if ($form->validate()) {
  70.     $clean = $form->getSubmitValues();
  71.  
  72.     echo '<pre>';
  73.     print_r($clean);
  74.     echo '</pre>';
  75. }
  76. $form->display();
  77. ?>
  78. </body>
  79. </html>
HTML_QuickForm_advmultiselect : The Definitive Guide v 1.4.0 : 9 Juin 2007