RE: [SMARTY-DEV] Checkbox syntax

From: Date: Mon, 05 May 2003 20:07:12 +0000
Subject: RE: [SMARTY-DEV] Checkbox syntax
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-1363@lists.php.net to get a copy of this message
Or cleaner, assign the data in the format the template expects. if(!isset($_POST['mychecks'])) [ $_POST['mychecks'] = array(); } $smarty->assign_by_ref('POST', $_POST); On Mon, 2003-05-05 at 14:53, luis wrote: > Ah, got it, if no checkboxes are set the array does not exist.... > Just add > {if $smarty.request.mychecks and > in_array(.....,$smarty.request.mychecks)}checked="checked"{/if} > > Thanks a lot Monte. > > -----Original Message----- > From: Monte Ohrt [mailto:monte@ispi.net] > Sent: Monday, May 05, 2003 4:49 PM > To: luis > Cc: 'Smarty Dev' > Subject: RE: [SMARTY-DEV] Checkbox syntax > > I expects an array. Dump out the content of the form results, see what > it is. > > print_r($_REQUEST); > > > On Mon, 2003-05-05 at 14:42, luis wrote: > > <checkbox name="mychecks[]" value="{$mychecks[foo].name}" > > {if > > > in_array($mycheckx[foo].name,$smarty.request.mychecks)}checked="checked" > > {/if} /> > > > > Error: wrong datatype for second argument, maybe > > $smarty.request.mychecks is not an array? > > > > > > -----Original Message----- > > From: Monte Ohrt [mailto:monte@ispi.net] > > Sent: Monday, May 05, 2003 4:34 PM > > To: luis > > Cc: 'Smarty Dev' > > Subject: RE: [SMARTY-DEV] Checkbox syntax > > > > If you're not using the {checkboxes} function, maybe use an array > > > > {if in_array($mychecks[foo], $selected_vals)} > > > > On Mon, 2003-05-05 at 14:31, luis wrote: > > > What do you put in the if? > > > {if $smarty.request.mychecks[??]}checked="checked"{/if} > > > > > > -----Original Message----- > > > From: Monte Ohrt [mailto:monte@ispi.net] > > > Sent: Monday, May 05, 2003 4:19 PM > > > To: luis > > > Cc: 'Smarty Dev' > > > Subject: Re: [SMARTY-DEV] Checkbox syntax > > > > > > Use an array instead of separately named checkboxes: > > > > > > <input type="checkbox" name="mychecks[]" > > > value="{$mychecks[foo]}" > {if > > > ..}checked="checked"{/if}> > > > > > > On Mon, 2003-05-05 at 14:15, luis wrote: > > > > Let's suposse I have checkboxes inside a section loop so the > "name" > > of > > > > each checkbox is: > > > > <input type="checkbox" name="{elements[$foo[ix]]}" /> > > > > > > > > I want to preserve checked boxes when processing a form in the > > script > > > .. > > > > Tried something like.. > > > > > > > > <input type="checkbox" name="{elements[$foo[ix]]}" {if > > > > $smarty.request.elements[$foo[ix]]}checked="checked"{/if} /> > > > > > > > > but it doesn't work. > > > > Which is the best way to do this? Maybe I'm overlooking something > > more > > > > elegant.. > > > > > > > > Luis > > > > > > -- > > Monte Ohrt <monte@ispi.net> > > > > > > -- > > Smarty Development Mailing List (http://smarty.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php -- Monte Ohrt <monte@ispi.net>

« previous php.smarty.dev (#1363) next »