cvs: peardoc /en/package/html html-quickform-advmultiselect.xml /en/package/html/html-quickform-advmultiselect/appendix examples-basic1.xml examples-custom1.xml examples-custom5.xml examples-custom7.xml examples-multiple1.xml examples-multiple2.xml examples-template1.xml
[email protected] ("Laurent Laville")
| Newsgroups | php.pear.doc |
|---|---|
| Message-ID | <cvsfarell1232794308@cvsserver> |
farell Sat Jan 24 10:51:48 2009 UTC
Added files:
/peardoc/en/package/html/html-quickform-advmultiselect/appendix
examples-basic1.xml
examples-custom1.xml
examples-custom5.xml
examples-custom7.xml
examples-multiple1.xml
examples-multiple2.xml
examples-template1.xml
Modified files:
/peardoc/en/package/html html-quickform-advmultiselect.xml
Log:
add examples appendix (screenshot will come alive when PhD will support it)
farell-20090124105148.txt
(text/plain, 38.6 KB)
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect.xml?r1=1.17&r2=1.18&diff_format=u
Index: peardoc/en/package/html/html-quickform-advmultiselect.xml
diff -u peardoc/en/package/html/html-quickform-advmultiselect.xml:1.17 peardoc/en/package/html/html-quickform-advmultiselect.xml:1.18
--- peardoc/en/package/html/html-quickform-advmultiselect.xml:1.17 Fri Jan 23 18:22:36 2009
+++ peardoc/en/package/html/html-quickform-advmultiselect.xml Sat Jan 24 10:51:47 2009
@@ -324,4 +324,16 @@
</section>
</chapter>
+ <chapter xml:id="package.html.html-quickform-advmultiselect.appendix">
+ <info><title>Examples appendix</title></info>
+
+ &package.html.html-quickform-advmultiselect.appendix.examples-basic1;
+ &package.html.html-quickform-advmultiselect.appendix.examples-custom1;
+ &package.html.html-quickform-advmultiselect.appendix.examples-custom7;
+ &package.html.html-quickform-advmultiselect.appendix.examples-custom5;
+ &package.html.html-quickform-advmultiselect.appendix.examples-multiple1;
+ &package.html.html-quickform-advmultiselect.appendix.examples-template1;
+ &package.html.html-quickform-advmultiselect.appendix.examples-multiple2;
+ </chapter>
+
</book>
\ No newline at end of file
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-basic1.xml?view=markup&rev=1.1
Index: peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-basic1.xml
+++ peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-basic1.xml
<?xml version="1.0" encoding="utf-8"?>
<section xml:id="package.html.html-quickform-advmultiselect.appendix.examples-basic1">
<info><title>Basic usage</title></info>
<para>
<figure>
<title xml:id="package.html.html-quickform-advmultiselect.appendix.examples-basic1-sscaption">Basic usage with default layout</title>
<screenshot>
<mediaobject>
<alt>qfams_basic_1.php script result</alt>
<imageobject>
<imagedata align="center" format="png" fileref="img/basic1.png"/>
</imageobject>
</mediaobject>
</screenshot>
</figure>
</para>
<para>
This example has no particular goals. It should be your first run to show
and handle a advmultiselect element that will emulate a multi-select.
</para>
<para>
<example>
<title>Without any customization</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Basic advMultiSelect HTML_QuickForm element
* without any customization.
*
* @version $Id: examples-basic1.xml,v 1.1 2009/01/24 10:51:48 farell Exp $
* @author Laurent Laville <[email protected]>
* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_basic_1.php
* qfams_basic_1 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/basic1.png
* screenshot (Image PNG, 406x247 pixels) 4.95 Kb
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsBasic1');
$form->removeAttribute('name'); // XHTML compliance
$car_array = array(
'dodge' => 'Dodge',
'chevy' => 'Chevy',
'bmw' => 'BMW',
'audi' => 'Audi',
'porsche' => 'Porsche',
'kia' => 'Kia',
'subaru' => 'Subaru',
'mazda' => 'Mazda',
'isuzu' => 'Isuzu',
);
// rendering with all default options
$form->addElement('header', null, 'Advanced Multiple Select: default layout ');
$form->addElement('advmultiselect', 'cars', 'Cars:', $car_array);
if (isset($_POST['cars'])) {
$form->setDefaults(array('cars' => $_POST['cars']));
}
$form->addElement('submit', 'send', 'Send');
?>
<!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 basic example 1</title>
<style type="text/css">
<!--
body {
background-color: #FFF;
font-family: Verdana, Arial, helvetica;
font-size: 10pt;
}
-->
</style>
</head>
<body>
<?php
if ($form->validate()) {
$clean = $form->getSubmitValues();
echo '<pre>';
print_r($clean);
echo '</pre>';
}
$form->display();
?>
</body>
</html>
]]>
</programlisting>
</example>
</para>
</section>
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-custom1.xml?view=markup&rev=1.1
Index: peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-custom1.xml
+++ peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-custom1.xml
<?xml version="1.0" encoding="utf-8"?>
<section xml:id="package.html.html-quickform-advmultiselect.appendix.examples-custom1">
<info><title>Extended usage</title></info>
<para>
<figure>
<title xml:id="package.html.html-quickform-advmultiselect.appendix.examples-custom1-sscaption">Custom usage with a simple template</title>
<screenshot>
<mediaobject>
<alt>qfams_custom_1.php script result</alt>
<imageobject>
<imagedata align="center" format="png" fileref="img/custom1.png"/>
</imageobject>
</mediaobject>
</screenshot>
</figure>
</para>
<para>
In this example, here are our goals :
<itemizedlist>
<listitem>
<simpara>change the buttons (add, remove) position. Move at bottom of lists.</simpara>
</listitem>
<listitem>
<simpara>center headers at top of lists.</simpara>
</listitem>
<listitem>
<simpara>set list item visible to 5. Default is 10.</simpara>
</listitem>
<listitem>
<simpara>enlarge both list width to 300 pixels. Default width is only 100 pixels.</simpara>
</listitem>
<listitem>
<simpara>change background colors element.</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title>Your first template element</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Custom advMultiSelect HTML_QuickForm element
* using stylesheet rules selectors and a template.
*
* The template allows to add label as headers of dual select box
* and moves the button to another location (below each select box).
*
* @version $Id: examples-custom1.xml,v 1.1 2009/01/24 10:51:48 farell Exp $
* @author Laurent Laville <[email protected]>
* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_custom_1.php
* qfams_custom_1 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/custom1.png
* screenshot (Image PNG, 677x197 pixels) 4.80 Kb
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsCustom1');
$form->removeAttribute('name'); // XHTML compliance
$fruit_array = array(
'apple' => 'Apple',
'orange' => 'Orange',
'pear' => 'Pear',
'banana' => 'Banana',
'cherry' => 'Cherry',
'kiwi' => 'Kiwi',
'lemon' => 'Lemon',
'lime' => 'Lime',
'tangerine' => 'Tangerine',
);
// rendering with QF renderer engine and template system
$form->addElement('header', null, 'Advanced Multiple Select: custom layout ');
$ams =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array,
array('size' => 5,
'class' => 'pool', 'style' => 'width:300px;'
)
);
$ams->setLabel(array('Fruit:', 'Available', 'Selected'));
$ams->setButtonAttributes('add', array('value' => 'Add >>',
'class' => 'inputCommand'
));
$ams->setButtonAttributes('remove', array('value' => '<< Remove',
'class' => 'inputCommand'
));
$template = '
<table{class}>
<!-- BEGIN label_2 --><tr><th align="center">{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th align="center">{label_3}</th></tr><!-- END label_3 -->
<tr>
<td>{unselected}</td>
<td>{selected}</td>
</tr>
<tr>
<td align="center">{add}</td>
<td align="center">{remove}</td>
</tr>
</table>';
$ams->setElementTemplate($template);
if (isset($_POST['fruit'])) {
$form->setDefaults(array('fruit' => $_POST['fruit']));
}
$form->addElement('submit', 'send', 'Send');
?>
<!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 custom example 1</title>
<style type="text/css">
<!--
body {
background-color: #FFF;
font-family: Verdana, Arial, helvetica;
font-size: 10pt;
}
table.pool {
border: 0;
background-color: lightyellow;
}
table.pool th {
font-size: 80%;
font-style: italic;
text-align: center;
}
table.pool select {
background-color: lightblue;
}
.inputCommand {
background-color: #d0d0d0;
border: 1px solid #7B7B88;
width: 7em;
margin-bottom: 2px;
}
-->
</style>
<?php echo $ams->getElementJs(false); ?>
</head>
<body>
<?php
if ($form->validate()) {
$clean = $form->getSubmitValues();
echo '<pre>';
print_r($clean);
echo '</pre>';
}
$form->display();
?>
</body>
</html>
]]>
</programlisting>
</example>
</para>
</section>
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-custom5.xml?view=markup&rev=1.1
Index: peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-custom5.xml
+++ peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-custom5.xml
<?xml version="1.0" encoding="utf-8"?>
<section xml:id="package.html.html-quickform-advmultiselect.appendix.examples-custom5">
<info><title>Sort usage</title></info>
<para>
<figure>
<title xml:id="package.html.html-quickform-advmultiselect.appendix.examples-custom5-sscaption">Auto-arrange feature usage</title>
<screenshot>
<mediaobject>
<alt>qfams_custom_5.php script result</alt>
<imageobject>
<imagedata align="center" format="png" fileref="img/custom5.png"/>
</imageobject>
</mediaobject>
</screenshot>
</figure>
</para>
<para>
In this example, here are our goals :
<itemizedlist>
<listitem>
<simpara>add the user-end sort buttons (up, down).</simpara>
</listitem>
<listitem>
<simpara>add the ability to sort lists in alphabetic order or reverse (by programming).</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title>How to sort the select boxes</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Custom advMultiSelect HTML_QuickForm element
* that allows to manage sort of select boxes.
*
* @version $Id: examples-custom5.xml,v 1.1 2009/01/24 10:51:48 farell Exp $
* @author Laurent Laville <[email protected]>
* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_custom_5.php
* qfams_custom_5 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/custom5.png
* screenshot (Image PNG, 609x318 pixels) 9.94 Kb
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsCustom5');
$form->removeAttribute('name'); // XHTML compliance
$fruit_array = array(
'apple' => 'Apple',
'orange' => 'Orange',
'pear' => 'Pear',
'banana' => 'Banana',
'cherry' => 'Cherry',
'kiwi' => 'Kiwi',
'lemon' => 'Lemon',
'lime' => 'Lime',
'tangerine' => 'Tangerine',
);
// decides either both select list will have their elements be arranged or not
if (isset($_POST['autoArrange'])) {
if ($_POST['autoArrange'] == 'A') {
$sort = SORT_ASC;
} elseif ($_POST['autoArrange'] == 'D') {
$sort = SORT_DESC;
} else {
$sort = false;
}
} else {
$sort = false;
}
// rendering with QF renderer engine and template system
$form->addElement('header', null,
'For demo purpose only: must be validate to be active');
$arrange[] =& $form->createElement('radio', null, null, 'Auto arrange asc.', 'A');
$arrange[] =& $form->createElement('radio', null, null, 'Auto arrange desc.', 'D');
$arrange[] =& $form->createElement('radio', null, null, 'No auto arrange', 'N');
$form->addGroup($arrange, 'autoArrange', 'Sort list:');
$form->setDefaults(array('autoArrange' => 'N'));
$validate =& $form->addElement('submit', null, 'Validate');
$form->addElement('header', null, 'Advanced Multiple Select: custom layout ');
$ams =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array,
array('class' => 'pool', 'style' => 'width:200px;'),
$sort
);
$ams->setLabel(array('Fruit:', 'Available', 'Selected'));
$ams->setButtonAttributes('add' , 'class=inputCommand');
$ams->setButtonAttributes('remove' , 'class=inputCommand');
$ams->setButtonAttributes('moveup' , 'class=inputCommand');
$ams->setButtonAttributes('movedown', 'class=inputCommand');
// template for a dual multi-select element shape
$template = '
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th> </th><th>{label_3}</th></tr><!-- END label_3 -->
<tr>
<td>{unselected}</td>
<td align="center">
{add}<br />{remove}<br /><br />{moveup}<br />{movedown}<br />
</td>
<td>{selected}</td>
</tr>
</table>
';
$ams->setElementTemplate($template);
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// fruit default values already selected without any end-user actions
$form->setDefaults(array('fruit' => array('kiwi','lime')));
} elseif (isset($_POST['fruit'])) {
// fruit end-user selection
$form->setDefaults(array('fruit' => $_POST['fruit']));
}
$buttons[] =& $form->createElement('submit', null, 'Submit');
$buttons[] =& $form->createElement('reset', null, 'Reset');
$form->addGroup($buttons);
?>
<!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 custom example 5</title>
<style type="text/css">
<!--
body {
background-color: #FFF;
font-family: Verdana, Arial, helvetica;
font-size: 10pt;
}
table.pool {
border: 0;
background-color: #339900;
}
table.pool td {
padding-left: 1em;
}
table.pool th {
font-size: 80%;
font-style: italic;
text-align: center;
}
table.pool select {
color: white;
background-color: #006600;
}
.inputCommand {
width: 60px;
}
-->
</style>
<?php echo $ams->getElementJs(false); ?>
</head>
<body>
<?php
if ($form->validate()) {
$clean = $form->getSubmitValues();
echo '<pre>';
print_r($clean);
echo '</pre>';
}
$form->display();
?>
</body>
</html>
]]>
</programlisting>
</example>
</para>
</section>
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-custom7.xml?view=markup&rev=1.1
Index: peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-custom7.xml
+++ peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-custom7.xml
<?xml version="1.0" encoding="utf-8"?>
<section xml:id="package.html.html-quickform-advmultiselect.appendix.examples-custom7">
<info><title>Advanced selection usage</title></info>
<para>
<figure>
<title xml:id="package.html.html-quickform-advmultiselect.appendix.examples-custom7-sscaption">Advanced selection</title>
<screenshot>
<mediaobject>
<alt>qfams_custom_7.php script result</alt>
<imageobject>
<imagedata align="center" format="png" fileref="img/custom7.png"/>
</imageobject>
</mediaobject>
</screenshot>
</figure>
</para>
<para>
In this example, here are our goals :
<itemizedlist>
<listitem>
<simpara>add buttons (all, none) to select / unselect all options in one stroke.</simpara>
</listitem>
<listitem>
<simpara>show two differents layout with checkboxes and dual selectboxes.</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title>How to do a global selection</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Custom advMultiSelect HTML_QuickForm element
* with extended buttons (select all, select none, toggle selection)
*
* @version $Id: examples-custom7.xml,v 1.1 2009/01/24 10:51:48 farell Exp $
* @author Laurent Laville <[email protected]>
* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_custom_7.php
* qfams_custom_7 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/custom7.png
* screenshot (Image PNG, 640x525 pixels) 160 Kb
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsCustom7');
$form->removeAttribute('name'); // XHTML compliance
$fruit_array = array(
'apple' => 'Apple',
'orange' => 'Orange',
'pear' => 'Pear',
'banana' => 'Banana',
'cherry' => 'Cherry',
'kiwi' => 'Kiwi',
'lemon' => 'Lemon',
'lime' => 'Lime',
'tangerine' => 'Tangerine',
);
// rendering with QF renderer engine and template system
$form->addElement('header', null, 'Advanced Multiple Select: custom layout ');
$ams =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array,
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');
// template for a single checkboxes multi-select element shape
$template1 = '
<table{class}>
<!-- BEGIN label_3 --><tr><th>{label_3}</th><th> </th></tr><!-- END label_3 -->
<tr>
<td>{selected}</td>
<td>{all}<br />{none}<br />{toggle}</td>
</tr>
</table>
';
// template for a dual multi-select element shape
$template2 = '
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th> </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 /><br />{moveup}<br />{movedown}<br />
</td>
<td>{selected}</td>
</tr>
</table>
';
if (isset($_POST['multiselect'])) {
$ams->setElementTemplate($template2);
} else {
$ams->setElementTemplate($template1);
}
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
// fruit default values already selected without any end-user actions
$form->setDefaults(array('fruit' => array('kiwi','lime')));
} elseif (isset($_POST['fruit'])) {
// fruit end-user selection
$form->setDefaults(array('fruit' => $_POST['fruit']));
}
$buttons[] =& $form->createElement('submit', null, 'Submit');
$buttons[] =& $form->createElement('reset', null, 'Reset');
$buttons[] =& $form->createElement('checkbox', 'multiselect', null,
'use dual select boxes layout');
$form->addGroup($buttons);
?>
<!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 custom example 7</title>
<style type="text/css">
<!--
body {
background-color: #FFF;
font-family: Verdana, Arial, helvetica;
font-size: 10pt;
}
table.pool {
border: 0;
background-color: cyan;
}
table.pool td {
padding-left: 1em;
}
table.pool th {
font-size: 80%;
font-style: italic;
text-align: center;
}
table.pool select {
color: gray;
background-color: #eee;
}
.inputCommand {
width: 120px;
}
<?php
if (!isset($_POST['multiselect'])) {
echo $ams->getElementCss();
}
?>
-->
</style>
<?php echo $ams->getElementJs(false); ?>
</head>
<body>
<?php
if ($form->validate()) {
$clean = $form->getSubmitValues();
echo '<pre>';
print_r($clean);
echo '</pre>';
}
$form->display();
?>
</body>
</html>
]]>
</programlisting>
</example>
</para>
</section>
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-multiple1.xml?view=markup&rev=1.1
Index: peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-multiple1.xml
+++ peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-multiple1.xml
<?xml version="1.0" encoding="utf-8"?>
<section xml:id="package.html.html-quickform-advmultiselect.appendix.examples-multiple1">
<info><title>Combines multiple elements</title></info>
<para>
<figure>
<title xml:id="package.html.html-quickform-advmultiselect.appendix.examples-multiple1-sscaption">Multiple usage with two different layouts</title>
<screenshot>
<mediaobject>
<alt>qfams_multiple_1.php script result</alt>
<imageobject>
<imagedata align="center" format="png" fileref="img/multiple1.png"/>
</imageobject>
</mediaobject>
</screenshot>
</figure>
</para>
<para>
In this example, here are our goals :
<itemizedlist>
<listitem>
<simpara>use two advmultiselect elements on the same page.</simpara>
</listitem>
<listitem>
<simpara>use two different layouts.</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title>Two different layouts on the same page</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Mixed advMultiSelect HTML_QuickForm elements.
* Two widgets on the same page/form with each its own javascript function
*
* @version $Id: examples-multiple1.xml,v 1.1 2009/01/24 10:51:48 farell Exp $
* @author Laurent Laville <[email protected]>
* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_multiple_1.php
* qfams_multiple_1 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/multiple1.png
* screenshot (Image PNG, 566x392 pixels) 8.82 Kb
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsMultiple1');
$form->removeAttribute('name'); // XHTML compliance
$fruit_array = array(
'apple' => 'Apple',
'orange' => 'Orange',
'pear' => 'Pear',
'banana' => 'Banana',
'cherry' => 'Cherry',
'kiwi' => 'Kiwi',
'lemon' => 'Lemon',
'lime' => 'Lime',
'tangerine' => 'Tangerine',
);
$car_array = array(
'dodge' => 'Dodge',
'chevy' => 'Chevy',
'bmw' => 'BMW',
'audi' => 'Audi',
'porsche' => 'Porsche',
'kia' => 'Kia',
'subaru' => 'Subaru',
'mazda' => 'Mazda',
'isuzu' => 'Isuzu',
);
// rendering with all default options
$form->addElement('header', null, 'Advanced Multiple Select: default layout ');
$ams1 =& $form->addElement('advmultiselect', 'cars', 'Cars:', $car_array);
if (isset($_POST['cars'])) {
$form->setDefaults(array('cars' => $_POST['cars']));
}
// rendering with css selectors and API selLabel(), setButtonAttributes()
$form->addElement('header', null, 'Advanced Multiple Select: custom layout ');
$ams2 =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array,
array('size' => 5,
'class' => 'pool', 'style' => 'width:200px;'
)
);
$ams2->setJsElement('fruit_');
$ams2->setLabel(array('Fruit:', 'Available', 'Selected'));
$ams2->setButtonAttributes('add', array('value' => 'Add', 'name' => 'add1',
'class' => 'inputCommand'
));
$ams2->setButtonAttributes('remove', array('value' => 'Remove', 'name' => 'remove1',
'class' => 'inputCommand'
));
if (isset($_POST['fruit'])) {
$form->setDefaults(array('fruit' => $_POST['fruit']));
}
$form->addElement('submit', 'send', 'Send');
?>
<!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 multiple example 1</title>
<style type="text/css">
<!--
body {
background-color: #FFF;
font-family: Verdana, Arial, helvetica;
font-size: 10pt;
}
table.pool {
border: 0;
background-color: #339900;
width:450px;
}
table.pool th {
font-size: 80%;
font-style: italic;
text-align: left;
}
table.pool select {
color: white;
background-color: #006600;
}
.inputCommand {
background-color: #d0d0d0;
border: 1px solid #7B7B88;
width: 7em;
margin-bottom: 2px;
}
// -->
</style>
<script type="text/javascript">
<!--
<?php
echo $ams1->getElementJs();
echo $ams2->getElementJs();
?>
-->
</script>
</head>
<body>
<?php
if ($form->validate()) {
$clean = $form->getSubmitValues();
echo '<pre>';
print_r($clean);
echo '</pre>';
}
$form->display();
?>
</body>
</html>
]]>
</programlisting>
</example>
</para>
</section>
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-multiple2.xml?view=markup&rev=1.1
Index: peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-multiple2.xml
+++ peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-multiple2.xml
<?xml version="1.0" encoding="utf-8"?>
<section xml:id="package.html.html-quickform-advmultiselect.appendix.examples-multiple2">
<info><title>Live counter combines with multiple elements</title></info>
<para>
<figure>
<title xml:id="package.html.html-quickform-advmultiselect.appendix.examples-multiple2-sscaption">Live counter on two advmultiselect elements</title>
<screenshot>
<mediaobject>
<alt>qfams_multiple_2.php script result</alt>
<imageobject>
<imagedata align="center" format="png" fileref="img/multiple2.png"/>
</imageobject>
</mediaobject>
</screenshot>
</figure>
</para>
<para>
In this example, here are our goals :
<itemizedlist>
<listitem>
<simpara>use two advmultiselect elements on the same page.</simpara>
</listitem>
<listitem>
<simpara>show two differents layout with checkboxes and dual selectboxes.</simpara>
</listitem>
<listitem>
<simpara>show two differents display of live counters with single and dual select boxes.</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title>Multiple live counters on same page</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Two advMultiSelect HTML_QuickForm elements with all properties
* that can be display in one or two select box mode.
* This example demonstrate the new feature of version 1.3.0 : Live Counter
*
* @version $Id: examples-multiple2.xml,v 1.1 2009/01/24 10:51:48 farell Exp $
* @author Laurent Laville <[email protected]>
* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_multiple_2.php
* qfams_multiple_2 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/multiple2.png
* screenshot (Image PNG, 595x511 pixels) 11.9 Kb
*/
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsMultiple2');
$form->removeAttribute('name'); // XHTML compliance
$fruit_array = array(
'apple' => 'Apple',
'orange' => 'Orange',
'pear' => 'Pear',
'banana' => 'Banana',
'cherry' => 'Cherry',
'kiwi' => 'Kiwi',
'lemon' => 'Lemon',
'lime' => 'Lime',
'tangerine' => 'Tangerine',
);
$car_array = array(
'dodge' => 'Dodge',
'chevy' => 'Chevy',
'bmw' => 'BMW',
'audi' => 'Audi',
'porsche' => 'Porsche',
'kia' => 'Kia',
'subaru' => 'Subaru',
'mazda' => 'Mazda',
'isuzu' => 'Isuzu',
);
// template for a single checkboxes multi-select element shape with live counter
$template1 = '
<table{class}>
<!-- BEGIN label_3 --><tr><th>{label_3}(<span id="{selected_count_id}">{selected_count}</span>)</th><th> </th></tr><!-- END label_3 -->
<tr>
<td>{selected}</td>
<td>{all}<br />{none}<br />{toggle}</td>
</tr>
</table>
';
// template for a dual multi-select element shape with live counter
$template2 = '
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}(<span id="{unselected_count_id}">{unselected_count}</span>)</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th> </th><th>{label_3}(<span id="{selected_count_id}">{selected_count}</span>)</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 />
</td>
<td>{selected}</td>
</tr>
</table>
';
$defaults = array();
// first QF ams element
$form->addElement('header', null, 'Advanced Multiple Select: Live Counter - pool1 style ');
$ams1 =& $form->addElement('advmultiselect', 'cars', null, $car_array,
array('size' => 10, 'class' => 'pool1', 'style' => 'width:200px;')
);
$ams1->setLabel(array('Cars:', 'Available', 'Selected'));
$ams1->setButtonAttributes('add', array('name' => 'add1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('remove', array('name' => 'remove1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('all', array('name' => 'all1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('none', array('name' => 'none1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('toggle', array('name' => 'toggle1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('moveup', array('name' => 'moveup1', 'class' => 'inputCommand'));
$ams1->setButtonAttributes('movedown', array('name' => 'movedown1', 'class' => 'inputCommand'));
if (isset($_POST['multiselect1'])) {
$ams1->setElementTemplate($template2);
} else {
$ams1->setElementTemplate($template1);
}
if (isset($_POST['cars'])) {
$defaults = array('cars' => $_POST['cars']);
}
// second QF ams element
$form->addElement('header', null, 'Advanced Multiple Select: Live Counter - pool2 style ');
$ams2 =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array,
array('size' => 5, 'class' => 'pool2', 'style' => 'width:300px;')
);
$ams2->setLabel(array('Fruit:', 'Available', 'Selected'));
$ams2->setButtonAttributes('add', array('name' => 'add2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('remove', array('name' => 'remove2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('all', array('name' => 'all2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('none', array('name' => 'none2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('toggle', array('name' => 'toggle2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('moveup', array('name' => 'moveup2', 'class' => 'inputCommand'));
$ams2->setButtonAttributes('movedown', array('name' => 'movedown2', 'class' => 'inputCommand'));
if (isset($_POST['multiselect2'])) {
$ams2->setElementTemplate($template2);
} else {
$ams2->setElementTemplate($template1);
}
if (isset($_POST['fruit'])) {
$defaults = array_merge($defaults, array('fruit' => $_POST['fruit']));
}
$buttons[] =& $form->createElement('submit', null, 'Submit');
$buttons[] =& $form->createElement('reset', null, 'Reset');
$buttons[] =& $form->createElement('checkbox', 'multiselect1', null,
'cars list dual select');
$buttons[] =& $form->createElement('checkbox', 'multiselect2', null,
'fruit list dual select');
$form->addGroup($buttons);
if (count($defaults) > 0) {
$form->setDefaults($defaults);
}
?>
<!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 multiple example 2</title>
<style type="text/css">
<!--
body {
background-color: #FFF;
font-family: Verdana, Arial, helvetica;
font-size: 10pt;
}
table.pool1, table.pool2 {
border: 0;
background-color: #339900;
width:450px;
}
table.pool2 {
background-color: #CFC;
}
table.pool1 th, table.pool2 th {
font-size: 80%;
font-style: italic;
text-align: left;
}
table.pool1 td, table.pool2 td {
vertical-align: top;
}
table.pool1 select, table.pool2 select {
color: white;
background-color: #006600;
}
.inputCommand {
background-color: #d0d0d0;
border: 1px solid white;
width: 9em;
margin-bottom: 2px;
}
<?php
if (!isset($_POST['multiselect1'])) {
echo $ams1->getElementCss();
}
if (!isset($_POST['multiselect2'])) {
echo $ams2->getElementCss();
}
?>
-->
</style>
<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>
</head>
<body>
<?php
if ($form->validate()) {
$clean = $form->getSubmitValues();
echo '<pre>';
print_r($clean);
echo '</pre>';
}
$form->display();
?>
</body>
</html>
]]>
</programlisting>
</example>
</para>
</section>
http://cvs.php.net/viewvc.cgi/peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-template1.xml?view=markup&rev=1.1
Index: peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-template1.xml
+++ peardoc/en/package/html/html-quickform-advmultiselect/appendix/examples-template1.xml
<?xml version="1.0" encoding="utf-8"?>
<section xml:id="package.html.html-quickform-advmultiselect.appendix.examples-template1">
<info><title>Template engine usage</title></info>
<para>
<figure>
<title xml:id="package.html.html-quickform-advmultiselect.appendix.examples-template1-sscaption">Template usage with Sigma engine</title>
<screenshot>
<mediaobject>
<alt>qfams_template_1.php script result</alt>
<imageobject>
<imagedata align="center" format="png" fileref="img/template1.png"/>
</imageobject>
</mediaobject>
</screenshot>
</figure>
</para>
<para>
In this example, here are our goals :
<itemizedlist>
<listitem>
<simpara>use a template engine.</simpara>
</listitem>
<listitem>
<simpara>see how to include a advmultiselect element.</simpara>
</listitem>
</itemizedlist>
</para>
<para>
<example>
<title>ITDynamic renderer with Sigma</title>
<programlisting role="php">
<![CDATA[
<?php
/**
* Custom advMultiSelect HTML_QuickForm element
* embedded into a Sigma template and using the QF dynamic renderer.
*
* @version $Id: examples-template1.xml,v 1.1 2009/01/24 10:51:48 farell Exp $
* @author Laurent Laville <[email protected]>
* @package HTML_QuickForm_advmultiselect
* @subpackage Examples
* @access public
* @example examples/qfams_template_1.php
* qfams_template_1 source code
* @link http://www.laurent-laville.org/img/qfams/screenshot/template1.png
* screenshot (Image PNG, 665x376 pixels) 23.3 Kb
*/
require_once 'HTML/Template/Sigma.php';
require_once 'HTML/QuickForm.php';
require_once 'HTML/QuickForm/Renderer/ITDynamic.php';
require_once 'HTML/QuickForm/advmultiselect.php';
$form = new HTML_QuickForm('amsTemplate1');
$form->removeAttribute('name'); // XHTML compliance
$fruit_array = array(
'apple' => 'Apple',
'orange' => 'Orange',
'pear' => 'Pear',
'banana' => 'Banana',
'cherry' => 'Cherry',
'kiwi' => 'Kiwi',
'lemon' => 'Lemon',
'lime' => 'Lime',
'tangerine' => 'Tangerine',
);
// rendering with css selectors and API selLabel(), setButtonAttributes()
$form->addElement('header', null, 'Advanced Multiple Select: custom layout ');
$form->addElement('text', 'name', 'Name:', array('size' => 40, 'maxlength' => 80));
$ams =& $form->addElement('advmultiselect', 'fruit', null, $fruit_array,
array('size' => 15,
'class' => 'pool', 'style' => 'width:150px;'
)
);
$ams->setLabel(array('Fruit:', 'Available', 'Selected'));
$ams->setButtonAttributes('add', array('value' => 'Add >>',
'class' => 'inputCommand'
));
$ams->setButtonAttributes('remove', array('value' => '<< Remove',
'class' => 'inputCommand'
));
$template = '
<table{class}>
<!-- BEGIN label_2 --><tr><th>{label_2}</th><!-- END label_2 -->
<!-- BEGIN label_3 --><th> </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($template);
if (isset($_POST['fruit'])) {
$form->setDefaults(array('fruit' => $_POST['fruit']));
}
$form->addElement('submit', 'send', 'Send', array('class' => 'inputCommand'));
$form->addRule('name', 'Your name is required', 'required');
$form->addGroupRule('fruit', 'At least one fruit is required', 'required', null, 1);
$form->applyFilter('__ALL__', 'trim');
$form->applyFilter('__ALL__', 'strip_tags');
$valid = $form->validate();
$tpl = new HTML_Template_Sigma('.');
$tpl->loadTemplateFile('itdynamic.html');
$tpl->setVariable('ams_javascript', $ams->getElementJs(false));
$renderer = new HTML_QuickForm_Renderer_ITDynamic($tpl);
$form->accept($renderer);
$tpl->show();
if ($valid) {
$clean = $form->getSubmitValues();
printf("<p>Welcome <b>%s</b> you've selected these fruits:</p>",
$clean['name']);
echo implode(', ', $clean['fruit']);
}
?>
]]>
</programlisting>
</example>
</para>
</section>