2013-08-30 41 views
1

我的代码在Smarty的,在我的表格有许多复选框,当我检查那么它正确提交的DB,但我想的是:当我打开窗体下一步,然后“这应该是保持检查“早于检查。但我的表单不工作像这个功能。我有.tpl file.My代码如下:复选框表格后,检查了智者提交

<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"> 

回答

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}/> 
+0

谢谢你的帮助,我明白了。 – samarth

+1

很高兴帮助。如果它解决了您的问题,请不要忘记接受答案,以便您的问题可以关闭。 –

0

我不太清楚你想要什么,但你可以用里面的代码的条件和发送给Smarty检查输入为了此时,相应的值触发条件,即:

<input type="checkbox" name="plan_type[{$record.id}][]" value="{$type}" {if $recordcheck}checked="checked"{/if}/> 
+0

我想选中复选框即使表单提交后..... – samarth

+0

Smarty的本身并不能知道你想要什么,除非你传递一个变量,所以你必须使用PHP决定是否需要检查复选框并传递布尔变量。即$ smarty-> assign('recordcheck',true); – Borgtex