我在smarty中编码,在我的表单中有许多复选框,当我检查它然后在DB中正确提交它,但我想要:当我打开表格然后“它应该保持检查”如早期检查。但我的表格不像这个功能那样工作。我有.tpl文件。我的代码在下面:
<div class="header_text">Brand</div>
<table style="margin-left: 94px;">
{foreach from=$interests item=record}
<tr>
<td style="width: 150px;">
<div class="interest_name">
<div class="interest_name">
{$record.name}
</div>
</div>
</td>
{foreach from=$record.type item=type}
<td style="width: 150px;">
{* I want to check checkbox after form submit based on Previously selected Form Submission*}
<input type="checkbox" name="plan_type[{$record.id}][]" value="{$type}" />
{$type}
<div id="comments">
<textarea name="comments[{$record.id}][]" cols="7" rows="2" value="comment"></textarea>
</div>
</td>
{/foreach}
<td style="...">
<input type="checkbox" name="shop" value="Shop" />Shop
<textarea name="comments[{$record.id}][]" cols="7" rows="2" value="comment"></textarea>
</td>
</tr>
{/foreach}
</tr>
<div class="shaukk-buttons universal-red-button home-page-buttons">
<a herf="#">Add Details</a>
</table>
<input type="submit" value="enter" name="submit">
答案 0 :(得分:3)
您需要通过php传递值:
global $smarty;
if(isset($_POST["checkboxname"])){
$smarty->assign("checkboxvalue", $_POST["checkboxname"]);
}
然后在你的模板中:
<input type="checkbox" name="checkboxname" value="{$type}" {if !empty($checkboxvalue) && $checkboxvalue == $type}checked="checked"{/if}/>
答案 1 :(得分:0)
我不太确定你想要什么,但你可以只使用代码中的条件来检查输入并发送适当的值来触发条件,即:
<input type="checkbox" name="plan_type[{$record.id}][]" value="{$type}" {if $recordcheck}checked="checked"{/if}/>