cvs: peardoc /en/package/html/html-quickform html-quickform-hierselect.xml
| From: | Martin Jansen | Date: | Tue, 05 Oct 2004 20:22:13 +0000 |
| Subject: | cvs: peardoc /en/package/html/html-quickform html-quickform-hierselect.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-4941@lists.php.net to get a copy of this message | ||
mj Tue Oct 5 16:22:13 2004 EDT
Modified files:
/peardoc/en/package/html/html-quickform
html-quickform-hierselect.xml
Log:
* Changed the example to remove deprecated elements and added a new
example.
Patch by: Aaron Wormus
http://cvs.php.net/diff.php/peardoc/en/package/html/html-quickform/html-quickform-hierselect.xml?r1=1.2&r2=1.3&ty=u
Index: peardoc/en/package/html/html-quickform/html-quickform-hierselect.xml
diff -u peardoc/en/package/html/html-quickform/html-quickform-hierselect.xml:1.2
peardoc/en/package/html/html-quickform/html-quickform-hierselect.xml:1.3
--- peardoc/en/package/html/html-quickform/html-quickform-hierselect.xml:1.2 Wed Sep 29 10:17:50
2004
+++ peardoc/en/package/html/html-quickform/html-quickform-hierselect.xml Tue Oct 5 16:22:12 2004
@@ -1,9 +1,9 @@
-<!-- $Revision: 1.2 $ -->
+<!-- $Revision: 1.3 $ -->
<refentry id="package.html.html-quickform.html-quickform-hierselect">
<refnamediv>
<refname>Class Summary
<classname>HTML_QuickForm_hierselect</classname></refname>
- <refpurpose>Class to dynamically create two HTML Select elements The first select
-changes the content of the second select.</refpurpose>
+ <refpurpose>Class to dynamically create chained HTML Select elements, each select
+changes the content of the next.</refpurpose>
</refnamediv>
<refsect1>
&title.desc;
@@ -11,19 +11,70 @@
changes the content of the second select and so on.</para>
<para>This element is considered as a group. Selects will be named groupName[0],
groupName[1], ...
<example>
- <title></title>
+ <title>Creating a hierselect element based on values from a database table</title>
<programlisting role="php">
<![CDATA[
+require_once 'HTML/QuickForm.php';
+$form = new HTML_QuickForm('example');
+
$form->setDefaults(array('test' => array('4','15')));
$sel =& $form->addElement('hierselect', 'test', 'Test:', null,
'/');
+
$mainOptions = $db->getAssoc('select pkparent, par_desc from parent');
-$sel->setMainOptions($mainOptions);
$result = $db->query("select fk_parent, pkchild, chi_desc from child");
while ($result->fetchInto($row)) {
$secOptions[$row[0]][$row[1]] = $row[2];
}
-$sel->setSecOptions($secOptions);
+// Using setMainOptions and setSecOptions is now deprecated
+// use setOptions.
+
+$sel->setOptions(array($mainOptions, $secOptions));
+
+$form->display();
+]]>
+ </programlisting>
+</example>
+Creating more than two select elements is just as simple.
+<example>
+ <title>Creating a hierselect element with three select elements</title>
+ <programlisting role="php">
+<![CDATA[
+require_once 'HTML/QuickForm.php';
+$form = new HTML_QuickForm('example');
+
+$select1[0] = 'Pop';
+$select1[1] = 'Classical';
+$select1[2] = 'Funeral doom';
+
+// second select
+$select2[0][0] = '--- Artist ---';
+$select2[0][1] = 'Red Hot Chil Peppers';
+$select2[0][2] = 'The Pixies';
+
+$select2[1][0] = '--- Artist ---';
+$select2[1][1] = 'Wagner';
+$select2[1][2] = 'Strauss';
+
+$select2[2][0] = '--- Artist ---';
+$select2[2][1] = 'Pantheist';
+$select2[2][2] = 'Skepticism';
+
+// Create a third select with prices for the cds
+$select3[0][1][0] = '15.00$';
+$select3[0][2][1] = '17.00$';
+$select3[1][1][0] = '15.00$';
+$select3[1][2][1] = '17.00$';
+$select3[2][1][0] = '15.00$';
+$select3[2][2][1] = '17.00$';
+
+// Create the Element
+$sel =& $form->addElement('hierselect', 'cds', 'Choose CD:');
+
+// And add the selection options
+$sel->setOptions(array($select1, $select2, $select3));
+
+$form->display();
]]>
</programlisting>
</example>