|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
bimal Smarty Elite
Joined: 19 Apr 2007 Posts: 423
|
Posted: Fri Nov 06, 2009 8:15 am Post subject: Missing in Manual - Multiple Checkboxes with {html_checkbox} |
|
|
What I am going to explain here is not explained by examples, in the Smarty Manual.
This is the case with {html_checkboxes} where I want to assign multiple items be selected by default. I am simply modifing the existing example here:
In the php:
Code: | $smarty->assign('cust_checkboxes', array(
1000 => 'Joe Schmoe',
1001 => 'Jack Smith',
1002 => 'Jane Johnson',
1003 => 'Charlie Brown'));
#$smarty->assign('customer_id', 1001); # Forget this!
$smarty->assign('customer_id', array(1002, 1003)); |
In the template:
Code: | {html_checkboxes name="id" options=$cust_checkboxes selected=$customer_id separator="<br />"} |
Output:
Code: | <label><input type="checkbox" name="id[]" value="1000" />Joe Schmoe</label><br />
<label><input type="checkbox" name="id[]" value="1001" />Jack Smith</label><br />
<label><input type="checkbox" name="id[]" value="1002" checked="checked" />Jane Johnson</label><br />
<label><input type="checkbox" name="id[]" value="1003" checked="checked" />Charlie Brown</label><br /> |
Have you noticed that the last two items are selected by default? |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Nov 06, 2009 3:06 pm Post subject: |
|
|
Yep, the "selected" attribute can be a string or array, as shown in the attribute table in the manual. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|