HTML_QuickForm_advmultiselect
[ class tree: HTML_QuickForm_advmultiselect ] [ index: HTML_QuickForm_advmultiselect ] [ all elements ]

Source for file qfams_basic_2.php

Documentation is available at qfams_basic_2.php

  1. <?php
  2. /**
  3.  * Basic advMultiSelect HTML_QuickForm element without any customization.
  4.  * Load options from a database.
  5.  *
  6.  * @version    $Id: qfams_basic_2.php,v 1.3 2008/04/26 17:25:59 farell Exp $
  7.  * @author     Laurent Laville <pear@laurent-laville.org>
  8.  * @package    HTML_QuickForm_advmultiselect
  9.  * @subpackage Examples
  10.  * @access     public
  11.  * @example    examples/qfams_basic_2.php
  12.  *              qfams_basic_2 source code
  13.  * @link       http://www.laurent-laville.org/img/qfams/screenshot/basic2.png
  14.  *              screenshot (Image PNG, 605x283 pixels) 5.17 Kb
  15.  */
  16.  
  17. require_once 'DB.php';
  18. require_once 'HTML/QuickForm.php';
  19. require_once 'HTML/QuickForm/advmultiselect.php';
  20. require_once 'dsn_qfams_basic2.inc';  // dsn data: $user, $pass, @$host, $db
  21.  
  22. PEAR::setErrorHandling(PEAR_ERROR_DIE);
  23.  
  24. $dsn = "mysql://$user:$pass@$host/$db";
  25.  
  26. $db = DB::connect($dsn);
  27.  
  28. // query to get all users of group #1 (available users list)
  29. $queryAll 'SELECT userid, CONCAT(lastname, " ", firstname) AS useridentity '
  30.           . 'FROM user WHERE gid = 1';
  31.  
  32. // query to get all users affected of group #1 (selected users list)
  33. $querySel 'SELECT userid FROM user WHERE gid = 1 AND affect = 1';
  34.  
  35. // execute query to get ident of users affected
  36. $affected_user =$db->getCol($querySel);
  37.  
  38.  
  39. $form = new HTML_QuickForm('amsBasic2');
  40. $form->removeAttribute('name');  // XHTML compliance
  41.  
  42. // same as default element template but wihtout the label (in first td cell)
  43. $withoutLabel = <<<_HTML
  44. <tr valign="top">
  45.     <td align="right">
  46.         &nbsp;
  47.     </td>
  48.     <td align="left">
  49.         <!-- BEGIN error --><span style="color: #ff0000;">{error}</span><br /><!-- END error -->{element}
  50.     </td>
  51. </tr>
  52. _HTML;
  53.  
  54. // more XHTML compliant
  55. // replace default element template with label, because submit button have no label
  56. $renderer =$form->defaultRenderer();
  57. $renderer->setElementTemplate($withoutLabel'send');
  58.  
  59. $form->addElement('header'null'Advanced Multiple Select: default layout ');
  60.  
  61. $ams =$form->addElement('advmultiselect''user',
  62.     array('Users:''Available''Affected'),         // labels
  63.     null,                                             // datas
  64.     array('style' => 'width:200px;')                  // custom layout
  65. );
  66.  
  67. // load QFAMS values (unselected and selected)
  68. $ams->load($db$queryAll'useridentity''userid'$affected_user);
  69.  
  70. $form->addElement('submit''send''Send');
  71.  
  72. // close database connection
  73. $db->disconnect();
  74. ?>
  75. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  76.     "http://www.w3c.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  77. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  78. <head>
  79. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  80. <title>HTML_QuickForm::advMultiSelect basic example 2</title>
  81. <style type="text/css">
  82. <!--
  83. body {
  84.   background-color: #FFF;
  85.   font-family: Verdana, Arial, helvetica;
  86.   font-size: 10pt;
  87. }
  88. pre.sql {
  89.   border: 1px solid silver;
  90.   background-color: lightyellow;
  91.   color: black;
  92.   padding: 1em;
  93. }
  94.  -->
  95. </style>
  96. <?php echo $ams->getElementJs(false)?>
  97. </head>
  98. <body>
  99. <?php
  100. if ($form->validate()) {
  101.     $clean $form->getSubmitValues();
  102.  
  103.     echo '<pre>';
  104.     print_r($clean);
  105.     echo '</pre>';
  106. else {
  107.     $form->display();
  108. }
  109. ?>
  110.  
  111. <pre class="sql">
  112. CREATE TABLE user (
  113.    userid VARCHAR(5) NOT NULL,
  114.    gid INT NOT NULL,
  115.    affect INT NOT NULL,
  116.    lastname VARCHAR(50)NOT NULL,
  117.    firstname VARCHAR(50) NOT NULL,
  118.    PRIMARY KEY (userid)
  119. );
  120.  
  121. INSERT INTO user VALUES ('MJ001', 1, 0, 'Martin', 'Jansen');
  122. INSERT INTO user VALUES ('BG001', 1, 1, 'Greg', 'Beaver');
  123. INSERT INTO user VALUES ('CD001', 1, 0, 'Daniel', 'Convissor');
  124. INSERT INTO user VALUES ('LL001', 2, 1, 'Laurent', 'Laville');
  125. </pre>
  126.  
  127. </body>
  128. </html>

Documentation generated on Sat, 26 Apr 2008 14:30:09 -0400 by phpDocumentor 1.4.0. PEAR Logo Copyright © PHP Group 2004.