View previous topic :: View next topic |
Author |
Message |
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu May 27, 2004 7:56 pm Post subject: SmartyFormtool: a javascript tool for your forms |
|
|
If you have ever had the need to do javascript tricks in your forms such as check-all, check-none, re-order, move from one list box to the other, etc. then this collection of plugins will help ease the pain.
http://www.phpinsider.com/php/code/SmartyFormtool/
This is the first release. I've only tested them in Mozilla and IE, although the functions are basic enough that they should work across the board. It has been an indispensible tool for me, so here it is in hopes it will help you too.
Enjoy!
Last edited by mohrt on Fri May 28, 2004 2:15 pm; edited 1 time in total |
|
Back to top |
|
xces Smarty Regular
Joined: 09 Apr 2004 Posts: 77
|
Posted: Fri May 28, 2004 6:59 am Post subject: |
|
|
The demo works with Firefox 0.8. |
|
Back to top |
|
TuMadre Smarty Rookie
Joined: 13 Jun 2004 Posts: 12
|
Posted: Sun Jun 13, 2004 9:36 am Post subject: |
|
|
I tried the 5th example (moving items from one multiselectbox to another), but the buttons did not show up in the browser.
I added {formtool_init src="/formtool.js"} to the top of the template, and the function.*.php are in the smarty plugins dir.
I even created a $colors array, so I could cut-and-paste from the example page, but to no effect; both selectboxes appear with their contents, but the buttons to move items between the two, don't apear.
I verified that the function.*.php files and formtool.js are in place and accessible.
Any suggestions? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Jun 13, 2004 3:32 pm Post subject: |
|
|
TuMadre wrote: | I tried the 5th example (moving items from one multiselectbox to another), but the buttons did not show up in the browser.
I added {formtool_init src="/formtool.js"} to the top of the template, and the function.*.php are in the smarty plugins dir.
I even created a $colors array, so I could cut-and-paste from the example page, but to no effect; both selectboxes appear with their contents, but the buttons to move items between the two, don't apear.
I verified that the function.*.php files and formtool.js are in place and accessible.
Any suggestions? |
what browser are you using? did you try the demo?
http://www.phpinsider.com/php/code/SmartyFormtool/demo/ |
|
Back to top |
|
TuMadre Smarty Rookie
Joined: 13 Jun 2004 Posts: 12
|
Posted: Sun Jun 13, 2004 5:28 pm Post subject: |
|
|
Using IE6, and the demo works fine... |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Sun Jun 13, 2004 6:50 pm Post subject: |
|
|
If the buttons don't appear (generated by the {formtool ... } function) then check that the funtions are being found by Smarty and executed. You should get a Smarty error though... caching is off right?
check the javascript console too, it could be that formtool.js is not found. with your example, it should be in the doc root. |
|
Back to top |
|
TuMadre Smarty Rookie
Joined: 13 Jun 2004 Posts: 12
|
Posted: Sun Jun 13, 2004 7:00 pm Post subject: |
|
|
I get:
Code: | Warning: Smarty error: formtool_moveup: missing 'save_from' parameter in /usr/local/WWW/games.xs4all.nl/htdocs/misc/bans/smarty/Smarty.class.php on line 1102
Warning: Smarty error: formtool_moveup: missing 'save_from' parameter in /usr/local/WWW/games.xs4all.nl/htdocs/misc/bans/smarty/Smarty.class.php on line 1102
Warning: Smarty error: formtool_moveup: missing 'save_from' parameter in /usr/local/WWW/games.xs4all.nl/htdocs/misc/bans/smarty/Smarty.class.php on line 1102
Warning: Smarty error: formtool_moveup: missing 'save_from' parameter in /usr/local/WWW/games.xs4all.nl/htdocs/misc/bans/smarty/Smarty.class.php on line 1102 |
I get nothing in javascript console (reference to formtool.js is correct, and file exists) |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jun 14, 2004 2:11 am Post subject: |
|
|
ah, supply a save parameter for them, being a hidden form value. I think the examples are missing them, and it doesn't do much good to use the formtools and not save the data somewhere. That one requires "save_from" and "save_to" since there are two to save.
{formtool ... save_to="save_to" save_from="save_from"}
<input type="hidden" name="save_to">
<input type="hidden" name="save_from"> |
|
Back to top |
|
TuMadre Smarty Rookie
Joined: 13 Jun 2004 Posts: 12
|
Posted: Mon Jun 14, 2004 7:59 am Post subject: |
|
|
mohrt wrote: | ah, supply a save parameter for them, being a hidden form value. I think the examples are missing them, and it doesn't do much good to use the formtools and not save the data somewhere. That one requires "save_from" and "save_to" since there are two to save.
{formtool ... save_to="save_to" save_from="save_from"}
<input type="hidden" name="save_to">
<input type="hidden" name="save_from"> |
OK, I'm kinda new to this all, and I don't understand what needs to be on the dots, and where to put the hidden formfields.
Could you please update your example below so it includes all necessary details? That would be greatly appreciated.
Code: | <table border=1>
<tr>
<td valign="top">
<select name="colors5[]" multiple size="10">
{html_options values=$colors output=$colors}
</select>
<input type="hidden" name="colors5_save">
</td>
<td align="center">
{formtool_moveall from="colors5[]" to="colors6[]" button_text=">&"}<br />
{formtool_move from="colors5[]" to="colors6[]" button_text="&"}<br />
{formtool_move from="colors6[]" to="colors5[]" button_text="&"}<br />
{formtool_moveall from="colors6[]" to="colors5[]" button_text="<&"}
</td>
<td valign="top">
<select name="colors6[]" multiple size="10">
</select>
<input type="hidden" name="colors6_save">
</td>
</tr>
</table> |
Thanks in advance! |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jun 14, 2004 1:43 pm Post subject: |
|
|
You just need to tell each formtool button where to save the data to when you click one. There needs to be two hidden fields anywhere on the form to save to.
Code: |
<table border=1>
<tr>
<td valign="top">
<select name="colors5[]" multiple size="10">
{html_options values=$colors output=$colors}
</select>
<input type="hidden" name="colors5_save">
</td>
<td align="center">
{formtool_moveall from="colors5[]" to="colors6[]" button_text=">&" save_from="colors5_save" save_to="colors6_save"}<br />
{formtool_move from="colors5[]" to="colors6[]" button_text="&" save_from="colors5_save" save_to="colors6_save"}<br />
{formtool_move from="colors6[]" to="colors5[]" button_text="&" save_from="colors5_save" save_to="colors6_save"}<br />
{formtool_moveall from="colors6[]" to="colors5[]" button_text="<&" save_from="colors5_save" save_to="colors6_save"}
</td>
<td valign="top">
<select name="colors6[]" multiple size="10">
</select>
<input type="hidden" name="colors5_save">
<input type="hidden" name="colors6_save">
</td>
</tr>
</table>
|
When you submit the form, colors5_save and colors6_save will contain a comma-separated list of values corresponding to the two option lists and their new values. |
|
Back to top |
|
TuMadre Smarty Rookie
Joined: 13 Jun 2004 Posts: 12
|
Posted: Mon Jun 14, 2004 8:57 pm Post subject: |
|
|
OK...
- formtool.js is in place and correctly referred to from the template.
- I copied the example (including save from and save to)
- I created the array, so I could test the same setup as the one in your example
Now the buttons are displayed correctly, but clicking them generates a JS error (object required)
I'm using IE6, so the javascript error messages aren't doing any good (they point to a line which is comment in formtool.js
Any more suggestions?
*update*
Even if I try to rebuild your example from scratch it generates JS errors. I'm probably doing something terribly wrong? ![Sad](images/smiles/icon_sad.gif) |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Jun 14, 2004 9:28 pm Post subject: |
|
|
Do you have a URL we can look at? |
|
Back to top |
|
TuMadre Smarty Rookie
Joined: 13 Jun 2004 Posts: 12
|
Posted: Mon Jun 14, 2004 9:38 pm Post subject: |
|
|
http://games.xs4all.nl/tester.php
tester.php
Code: | <?php
require("xxx/xxx/config.inc.php");
$colors = array(red,yellow,blue,orange,purple,green,brown,black,white);
$smarty = new dynamicPage;
$smarty->assign("colors",$colors);
$smarty->display('tester.tpl');
?> |
tester.tpl
Code: | {formtool_init src="/formtool.js"}
<table border=1>
<tr>
<td valign="top">
<select name="colors5[]" multiple size="10">
{html_options values=$colors output=$colors}
</select>
<input type="hidden" name="colors5_save">
</td>
<td align="center">
{formtool_moveall from="colors5[]" to="colors6[]" button_text=">>" save_from="colors5_save" save_to="colors6_save"}<br />
{formtool_move from="colors5[]" to="colors6[]" button_text=">" save_from="colors5_save" save_to="colors6_save"}<br />
{formtool_move from="colors6[]" to="colors5[]" button_text="<" save_from="colors5_save" save_to="colors6_save"}<br />
{formtool_moveall from="colors6[]" to="colors5[]" button_text="<<" save_from="colors5_save" save_to="colors6_save"}
</td>
<td valign="top">
<select name="colors6[]" multiple size="10">
</select>
<input type="hidden" name="colors5_save">
<input type="hidden" name="colors6_save">
</td>
</tr>
</table> |
|
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Mon Jun 14, 2004 10:31 pm Post subject: |
|
|
you seem to be missing one thing... an actual form! eg:
Code: | <form name="foobar" action="doit">
{formtool_checkall name="colors[]"}
....
</form> |
Check out the source for Monte's demo at http://www.phpinsider.com/php/code/SmartyFormtool/demo/ -- it has it in there. ![Wink](images/smiles/icon_wink.gif) |
|
Back to top |
|
TuMadre Smarty Rookie
Joined: 13 Jun 2004 Posts: 12
|
Posted: Mon Jun 14, 2004 10:38 pm Post subject: |
|
|
boots wrote: | you seem to be missing one thing... an actual form! eg:
Code: | <form name="foobar" action="doit">
{formtool_checkall name="colors[]"}
....
</form> |
Check out the source for Monte's demo at http://www.phpinsider.com/php/code/SmartyFormtool/demo/ -- it has it in there. ![Wink](images/smiles/icon_wink.gif) |
that was it
sorry for wasting your time (you might want to update the examples to prevent ppl like me fouling up) ![Very Happy](images/smiles/icon_biggrin.gif) |
|
Back to top |
|
|