2013-08-01 42 views
0

以下是我的代碼片段:如何在smarty中使用數組給出相同的名稱?

<tr height="30" id="user_option"> 
        <td width="300"> 
         <input type="checkbox" id="users" name="users" value="users"/>Users 
        </td> 
        <td>&nbsp;<input type="checkbox" id="upload_from_file" name="upload_from_file" value="upload_from_file"/>Upload From File 
        </td> 
        <td> 
        <input type="checkbox" id="copy_paste_from_excel" name="copy_paste_from_excel" value="copy_paste_from_excel"/>Copy paste from excel 
        </td> 
        </tr> 

這是智者的模板代碼。實際上,當我提交這個表單時,我想要一個包含複選框值的數組,以便實現我必須爲這些複選框使用相同的名稱。但我無法以這樣的方式命名複選框,以便在提交表單後可以將所有選中的複選框的值存儲在單個數組中。你能幫我實現這個目標嗎?提前致謝。

回答

1

定義複選框的名稱屬性是一個數組:

<input type="checkbox" id="id1" name="cb_data[var_name1]" value="some_val"/> 
<input type="checkbox" id="id2" name="cb_data[var_name2]" value="another_val"/> 

然後檢查$_POST['cb_data']陣列。

相關問題