2014-10-29 85 views
0

我使用Smarty處理表單。 有一些驗證使用正則表達式來檢查電話號碼和電子郵件。 如果一切正確,用戶可以跳到確認頁面,否則這些檢查將被保留。 我使用checkboxes_html和一些選項「selected」。 但是,如果驗證不成功,我所做的所有檢查都將消失。html_checkboxes Smarty

[PHP]

// Lists for the radio button 
$smarty->assign('genre_output', array('apple','chiken','tuna')); 
$smarty->assign('genre_values', array('apple','chiken','tuna')); 

[HTML]

<tr> 
<th>Genre</th> 
<td> 
{html_checkboxes name="genre" values=$genre_values output=$genre_output selected="{$data['genre']|escape}" separator='<br />'} 
</td> 
</tr> 
+0

顯示你在PHP中如何驗證並重新填充數據形成。 – 2014-10-29 08:45:08

回答

0

嘗試下面的代碼。它爲我的作品:

TPL文件:

<form action="" method="post"> 
    {html_checkboxes name="genre" values=$genre_values output=$genre_output selected=$genre_selected separator=""} 
    <input type="submit"> 
</form> 

php文件:

$smarty->assign('genre_output', array('apple','chiken','tuna')); 
$smarty->assign('genre_values', array('apple','chiken','tuna')); 
$smarty->assign('genre_selected', $_POST['genre']);