我必须与Symfony 1合作(是的,我知道它已经很老了)。我必须做一个表单,用户可以通过复选框输入多个选项。除了当我检查多个复选框时,我只获取最后一个复选框的内容
我有这个:
<tr>
<th>Est prolongé :</th>
<td>
<?php echo checkbox_tag('motif', '1'); ?>
</td>
</tr>
<tr>
<th>Est interrompu :</th>
<td>
<?php echo checkbox_tag('motif', '2'); ?>
</td>
</tr>
public function executeAddFormAvenant()
{
sfLoader::loadHelpers('Url');
// Enregistremant d'un nouvel avenant :
$avenant=new ConvFormAvenant();
$avenant->setIdConvConvention($this->getRequestParameter('id_convention'));
$conv_convention = ConvConventionPeer::retrieveByPk($this->getRequestParameter('id_convention'));
if ($this->getRequestParameter('motif')==1)
{
$avenant->setEstProlongé(1);
} else{
$avenant->setEstProlongé(0);
}
if ($this->getRequestParameter('motif')==2)
{
$avenant->setEstInterrompu(1);
} else{
$avenant->setEstInterrompu(0);
}
答案 0 :(得分:0)
在不了解checkbox_tag()
功能的情况下,我只建议将这些行中的第一个参数更改为motif[]
:
<?php echo checkbox_tag('motif', '1'); ?>
<?php echo checkbox_tag('motif', '2'); ?>
输出仍然在motif
下,没有括号。如果该参数用于命名复选框,则会将行为更改为具有值而不是单个值的数组。