Re: Smarty loops and check boxes
| From: | Bertrand Mansion | Date: | Thu, 14 Aug 2003 08:43:43 +0000 |
| Subject: | Re: Smarty loops and check boxes | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-7194@lists.php.net to get a copy of this message | ||
<graeme@inetix.com.au> wrote :
> Hi all.
> I've got a Smarty page that loops through an array to display a list of
> items which have a check box next to them. The idea is tha a user would
> select the items they want to remove and hot submit and they're gone.
>
> <form {$form.attributes}>
> {foreach from=$watches item=watch}
> {$watch.name} <!-- something goes here :) -->
> {/foreach}
> </form>
>
> This would get rendered as something like
> <form>
> One <checkbox name="remove[]" value="1">
> Two <checkbox name="remove[]" value="2">
> Three <checkbox name="remove[]" value="3">
> </form>
>
> I'm not sure how I can create the checkbox in Quickform yet build it into
> the loop in Smarty. Any help gratefully received.
Can't you just use a group with addGroup() ?
foreach ($item as $watch) {
$watchChbx[] =& HTML_QuickForm::createElement('checkbox', null, null,
$watch['name']);
}
$form->addGroup($checkbox, 'remove', 'Remove items:', '<br
/>');
You will get :
<form>
One <checkbox name="remove[0]" value="1">
Two <checkbox name="remove[1]" value="1">
Three <checkbox name="remove[2]" value="1">
</form>
Instead because of the way quickform handles checkboxes. You can change the
index by setting the second parameter in createElement.
HTH
Bertrand Mansion
Mamasam