2014-10-29 88 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']);