Re: [SMARTY] syntax
| From: | Ben Godfrey | Date: | Thu, 04 Jul 2002 15:13:42 +0000 |
| Subject: | Re: [SMARTY] syntax | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-5197@lists.php.net to get a copy of this message | ||
Hi Roger,
I don't think you can do this kind of variable name construction in Smarty.
Probably the easiest solution would be to pass an array to Smarty like this:
if ($submit) {
$tpl->assign("myvars", array(
array("name"=>"myvar1", "value"=>"$myvar1"),
array("name"=>"myvar2", "value"=>"$myvar2"),
array("name"=>"myvar3", "value"=>"$myvar3")
);
$tpl->assign("varname", "$varname");
}
$tpl->display("form.tpl");
Then access them like this:
<form action="{$smarty.server.PHP_SELF}">
<tr><td>name: <input type=text name=yourname value="{$myvars.varname}"></td></tr>
{section name=q loop=$z}
<tr>
<TD>
<input type=text name="{$myvar[q].name}"
value="{$myvar[q].value}">
</TD></tr> {/section} <tr><td><input type=submit name=submit value=submit></td></tr> </form> HTH, Ben On Thursday, July 4, 2002, at 03:58 , Roger Thomas wrote:
i cannot get the value portion of the <input ... > below working. lets say $z = 3. if $name is blank, i want to reprint the form, which is no problem BUT the 3 rows for myvar1, myvar2, myvar3 ALL consists of the values 1,2 and 3 ; whereas i have keyed in something else. i have checked that in my php script, after submitting the form, i have done this: if ($submit) {$tpl->assign(array(myvar1 => $myvar1, myvar2 => $myvar2, myvar3 => $myvar3, varname => $yourname));} else {$tpl->display("form.tpl");} form.tpl -------- <form action="<? echo $PHP_SELF ?>"> <tr><td>name: <input type=text name=yourname value="{$varname}"></td></tr> {section name=q loop=$z} <tr><TD> <input type=text name="myvar{$smarty.section.q.iteration}"value="{$myvar}{$smarty.section.q.iteration}"></TD></tr> {/section} <tr><td><input type=submit name=submit value=submit></td></tr> </form> please advise. rgds. __________________________________________________ Do You Yahoo!? Sign up for SBC Yahoo! Dial - First Month Free http://sbc.yahoo.com -- Smarty General Mailing List (http://smarty.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php