cvs: peardoc /en/package/html html-quickform-advmultiselect.xml /en/package/html/html-quickform-advmultiselect faq.xml

From: Date: Thu, 22 Jan 2009 15:02:11 +0000
Subject: cvs: peardoc /en/package/html html-quickform-advmultiselect.xml /en/package/html/html-quickform-advmultiselect faq.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-11467@lists.php.net to get a copy of this message
farell Thu Jan 22 15:02:11 2009 UTC Added files: /peardoc/en/package/html/html-quickform-advmultiselect faq.xml Modified files: /peardoc/en/package/html html-quickform-advmultiselect.xml Log: TDG migration phase1: prepare structure of new Manual pages, and implement the FAQ

http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect.xml?r1=1.7&r2=1.8&diff_format=u Index: peardoc/en/package/html/html-quickform-advmultiselect.xml diff -u peardoc/en/package/html/html-quickform-advmultiselect.xml:1.7 peardoc/en/package/html/html-quickform-advmultiselect.xml:1.8 --- peardoc/en/package/html/html-quickform-advmultiselect.xml:1.7 Thu Oct 9 22:35:25 2008 +++ peardoc/en/package/html/html-quickform-advmultiselect.xml Thu Jan 22 15:02:10 2009 @@ -9,7 +9,98 @@ </abstract> </info> - <chapter> - &package.html.html-quickform-advmultiselect.intro; + <chapter xml:id="package.html.html-quickform-advmultiselect.summary"> + <info><title>Summary</title></info> + + <section xml:id="package.html.html-quickform-advmultiselect.summary.use"> + <info><title>Why use HTML_QuickForm_advmultiselect ?</title></info> + <para> + I am sure we have all been there, dealing with HTML_QuickForm because we need + to allow users to select multiple options. + With a standard html select box, you can select multiple options if the + <emphasis>multiple</emphasis> attribute is set, but you have to hold down + the appropriate modifier key (ctrl on windows) in order to do so. + It is not a problem for end-user experts, but it is not true for all of us. + </para> + </section> + + <section xml:id="package.html.html-quickform-advmultiselect.summary.features"> + <info><title>Features</title></info> + <para> + <itemizedlist> + <listitem> + <simpara> + ability to double click on either select box to move elements from one side to the other + </simpara> + </listitem> + <listitem> + <simpara> + added headers to the select boxes + </simpara> + </listitem> + <listitem> + <simpara> + ability to change layout easily, using CSS classes and a mini template + </simpara> + </listitem> + <listitem> + <simpara> + allows to change item size shown of each multiple select box + </simpara> + </listitem> + <listitem> + <simpara> + JavaScript functions can be renamed to avoid conflict with others scripts on the same page + </simpara> + </listitem> + <listitem> + <simpara> + ability to manage one single list with checkboxes to solve problem if javascript is unavailable + </simpara> + </listitem> + <listitem> + <simpara> + ability to sort lists (by programming, or user-end handling) + </simpara> + </listitem> + <listitem> + <simpara> + display live counter (selected/unselected items count) + Available since version 1.3.0 + </simpara> + </listitem> + </itemizedlist> + </para> + </section> + + <section xml:id="package.html.html-quickform-advmultiselect.summary.requires"> + <info><title>System Requirements</title></info> + <para> + Mandatory resources : + <itemizedlist> + <listitem> + <para><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.php;">PHP</link> 4.3.10 or newer.</para> + </listitem> + <listitem> + <para><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.pear;">PEAR</link> 1.5.4 or newer.</para> + </listitem> + <listitem> + <para><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.pear.package;HTML_Common">PEAR::HTML_Common</link> 1.2.4 or newer.</para> + </listitem> + <listitem> + <para><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.pear.package;HTML_Quickform">PEAR::HTML_Quickform</link> 3.2.10 or newer.</para> + </listitem> + <listitem> + <para><link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.php;pcre">pcre</link> extension.</para> + </listitem> + </itemizedlist> + </para> + </section> + + <section xml:id="package.html.html-quickform-advmultiselect.summary.question"> + <info><title>About</title></info> + &package.html.html-quickform-advmultiselect.faq; + </section> </chapter> -</book> + +</book> \ No newline at end of file http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect/faq.xml?view=markup&rev=1.1 Index: peardoc/en/package/html/html-quickform-advmultiselect/faq.xml +++ peardoc/en/package/html/html-quickform-advmultiselect/faq.xml <?xml version="1.0" encoding="utf-8"?> <refentry xmlns="http://docbook.org/ns/docbook" version="lillet" xml:id="package.html.html-quickform-advmultiselect.faq"> <refnamediv> <refname>FAQ</refname> <refpurpose>Answers to most Frequently Asked Questions</refpurpose> </refnamediv> <refsection xml:id="package.html.html-quickform-advmultiselect.faq.content"> <info><title>HTML_QuickForm_advmultiselect FAQ</title></info> <qandaset> <qandadiv><title>General questions</title> <qandaentry> <question> <para>What does it cost ?</para> </question> <answer> <para> You can download and use it for free. But don't delete the copyright notice. You can read terms of the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.license.bsd;">license</link>. </para> </answer> </qandaentry> <qandaentry> <question> <para>Do you offer support ?</para> </question> <answer> <para> YES if there is no answer in this Guide and if you are ready to share some informations such as : your configuration (platform Win *nix mac, PHP version, PEAR packages installed) and perharps your script. </para> </answer> </qandaentry> <qandaentry> <question> <para>I found a bug, what shall i do ?</para> </question> <answer> <para> You can report it with the bug tracker at <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.pear.package;HTML_QuickForm_advmultiselect/bugs">PEAR</link>. </para> </answer> </qandaentry> <qandaentry> <question> <para>What is HTML_QuickForm ?</para> </question> <answer> <para> <emphasis role="bold">HTML_QuickForm</emphasis> is a PEAR package that provides methods for creating, validating and processing HTML forms. </para> <para> The purpose of <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="http://www.midnighthax.com/quickform.php">Keith Edmunds</link> tutorial is to give the new users of QuickForm an overview of its features and usage patterns. It describes a small subset of available functionality. </para> <para> Don't forget to read also the PEAR Manual, <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.pear.manual;en/package.html.html-quickform.php">HTML_QuickForm</link> related part. </para> </answer> </qandaentry> <qandaentry> <question> <para>What is PEAR ?</para> </question> <answer> <para> PEAR (an acronym for <emphasis role="bold">P</emphasis>HP <emphasis role="bold">E</emphasis>xtension and <emphasis role="bold">A</emphasis>pplication <emphasis role="bold">R</emphasis>epository) is a framework and distribution system for reusable PHP components. </para> <para> Don't forget to read also the <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.pear.manual;en">PEAR Manual</link> and <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.pear.manual;en/faq.php">PEAR FAQ</link>. </para> </answer> </qandaentry> </qandadiv> <qandadiv><title>How to</title> <qandaentry> <question> <para>May i use HTML_QuickForm_advmultiselect if my browser is no javascript compliant or if javascript is disabled ?</para> </question> <answer> <para> The dual multi-select won't work, but you can display a single multi select box witch checkboxes. To do so, you have to remove <emphasis role="bold">{unselected}</emphasis> placeholder in the advmultiselect template element. </para> </answer> </qandaentry> <qandaentry> <question> <para>How to validate a HTML_QuickForm_advmultiselect element ?</para> </question> <answer> <para> You must use the HTML_QuickForm <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.pear.manual;en/package.html.html-quickform.html-quickform.addgrouprule.php"> addGroupRule() </link> method rather than HTML_QuickForm <link xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="&url.pear.manual;en/package.html.html-quickform.html-quickform.addrule.php"> addRule() </link> method. </para> </answer> </qandaentry> <qandaentry> <question> <para>How to optimize javascript code usage on html generated page ?</para> </question> <answer> <caution> <simpara> Following answers can be applied only for HTML_QuickForm_advmultiselect version 1.3.0 or better. </simpara> </caution> <para> Use only once reference of javascript source code. If you have more than one advmultiselect element on your html page, then keep only one call and remove others. <programlisting role="php"> <![CDATA[ <script type="text/javascript"> <?php echo $ams1->getElementJs(); // keep one //echo $ams2->getElementJs(); // remove others ?> </script> ]]> </programlisting> </para> <para> Better solution is to use link to external resource and then reduce amount of javascript source code embedded. Add line of code below between &lt;head&gt; tags of your generated page. <programlisting role="html"> <![CDATA[ <script type="text/javascript" src="qfamsHandler.js"></script> ]]> </programlisting> <note> <para> Fix path to javascript resource if necessary. <filename>qfamsHandler.js</filename> file can be found in PEAR/data/HTML_QuickForm_advmultiselect directory. </para> </note> </para> <para> At least remove <literal>{javascript}</literal> placeholder if you use default template. You have to set this new one <literal>$deftpl</literal>, with code something like : <programlisting role="php"> <![CDATA[ <?php require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/advmultiselect.php'; $form = new HTML_QuickForm('ams130'); // .... $ams =& $form->addElement('advmultiselect', 'cars', null, $car_array); $deftpl = ' <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 valign="top">{unselected}</td> <td align="center">{add}{remove}</td> <td valign="top">{selected}</td> </tr> </table> '; $ams->setElementTemplate($deftpl); //... ?> ]]> </programlisting> </para> </answer> </qandaentry> </qandadiv> <qandadiv><title>Troubleshooting guide</title> <qandaentry> <question> <para> My Quickform advmultiselect element is not displayed on my browser window. </para> </question> <answer> <para> You should have forgotten to add package ressource itself. This operation is mandatory for all external Quickform elements and not necessary for internal elements such as "radio", "checkbox", "text", "button", ... </para> <para> <programlisting role="php"> <![CDATA[ <?php require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/advmultiselect.php'; // <-- DO NOT forget it ?> ]]> </programlisting> </para> </answer> </qandaentry> <qandaentry> <question> <para>My live counter is not updated with a single select list, when I click on checkboxes ?</para> </question> <answer> <para> With HTML_QuickForm_advmultiselect version 1.3.0 or better you need to add a chunk of javascript code to initialize onclick event handler of each checkboxes. <programlisting role="html"> <![CDATA[ <script type="text/javascript" src="qfamsHandler.js"></script> <script type="text/javascript"> window.qfamsName = new Array(); window.qfamsName[0] = 'cars'; window.qfamsName[1] = 'fruit'; window.addEventListener('load', qfamsInit, false); </script> ]]> </programlisting> <literal>window.qfamsName</literal> is an array what identify each advmultiselect element used on your html page. </para> </answer> </qandaentry> <qandaentry> <question> <para>The selected list has one blank entry that you can move to available list</para> </question> <answer> <para> This problem comes when you set the selected list (see HTML_QuickForm::setDefaults() method) with a wrong data array. </para> <para> Remember that the available list contains all datas (selected and unselected values). This list is an associative array of "key-code" => "display-value". While selected list is only an array of "key-code". </para> <para> Suppose we have to retrieve information from a database (with PEAR::DB), and have a simple table for holding user info. This SQL statement creates a table usable under the default database scheme using MySQL: <programlisting role="sql"> CREATE TABLE user ( userid VARCHAR(5) NOT NULL, gid INT NOT NULL, affect INT NOT NULL, lastname VARCHAR(50)NOT NULL, firstname VARCHAR(50) NOT NULL, PRIMARY KEY (userid) ); </programlisting> with values : <programlisting role="sql"> INSERT INTO user VALUES ('MJ001', 1, 0, 'Martin', 'Jansen'); INSERT INTO user VALUES ('BG001', 1, 1, 'Greg', 'Beaver'); INSERT INTO user VALUES ('CD001', 1, 0, 'Daniel', 'Convissor'); INSERT INTO user VALUES ('LL001', 2, 1, 'Laurent', 'Laville'); </programlisting> Column <emphasis>gid</emphasis> identify a user group, while <emphasis>userid</emphasis> identify a single and unique user. </para> <para> We will initialize AVAILABLE list (on left side if default template) by a db query something like that: <programlisting role="php"> <![CDATA[ <?php $queryAll = 'SELECT userid, CONCAT(lastname, " ", firstname) AS useridentity ' . 'FROM user WHERE gid = 1'; ?> ]]> </programlisting> and get this array: <programlisting> Array ( [MJ001] => Jansen Martin [BG001] => Beaver Greg [CD001] => Convissor Daniel ) </programlisting> </para> <para> We will initialize SELECTED list (on right side if default template) by a db query something like that: <programlisting role="php"> <![CDATA[ <?php // Once you have a valid DataBase object named $db ... $querySel = 'SELECT userid FROM user WHERE gid = 1 AND affect = 1'; $affected_user =& $db->getCol($querySel); ?> ]]> </programlisting> and get this array: <programlisting> Array ( [0] => BG001 ) </programlisting> <caution> <simpara> Remember that only a key-code array is necessary, other data will make blank line into select box. </simpara> </caution> </para> <para> Remains stuff is basic, create the QFAMS element, and load options (available and selected) with the QF/select element <methodname>load()</methodname> method. <programlisting role="php"> <![CDATA[ <?php require_once 'HTML/QuickForm.php'; require_once 'HTML/QuickForm/advmultiselect.php'; $form = new HTML_QuickForm('amsDB'); // Once you have a valid QuickForm advmultiselect object named $ams in a QuickForm named $form ... $ams =& $form->addElement('advmultiselect', 'user', array('Users:', 'Available', 'Affected'), // labels null, // datas: "key-code" => "display-value" array('style' => 'width:200px;') // custom layout ); $ams->load($db, $queryAll, 'useridentity', 'userid', $affected_user); // ... ?> ]]> </programlisting> <tip> <para> You may use the <methodname>load()</methodname> method to set options from : <programlisting role="php"> <![CDATA[ <?php // ... // 1. a php array $all_user = array('MJ001' => 'Martin Jansen', 'BG001' => 'Greg Beaver', 'CD001' => 'Daniel Convissor' ); $affected_user = array('BG001'); $ams->load($all_user, $affected_user); // queries to get data $queryAll = 'SELECT userid, CONCAT(lastname, " ", firstname) AS useridentity ' . 'FROM user WHERE gid = 1'; $querySel = 'SELECT userid FROM user WHERE gid = 1 AND affect = 1'; $affected_user =& $db->getCol($querySel); // 2. a db result $all_user =& $db->query($queryAll); $ams->load($all_user, 'useridentity', 'userid', $affected_user); // 3. a db query $ams->load($db, $queryAll, 'useridentity', 'userid', $affected_user); // ... ?> ]]> </programlisting> </para> </tip> <note> <simpara> This example is available in bundle (see examples/qfams_basic_2.php) </simpara> </note> </para> </answer> </qandaentry> </qandadiv> </qandaset> </refsection> </refentry>
« previous php.pear.doc (#11467) next »