【问题标题】:I can't the contents of my checkbox (symfony 1.0)我无法查看复选框的内容(symfony 1.0)
【发布时间】:2018-06-25 01:02:12
【问题描述】:

我必须使用 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);
    }

【问题讨论】:

  • 向我们展示checkbox_tag函数
  • function checkbox_tag($name, $value = '1', $checked = false, $options = array()) { $html_options = array_merge(array('type' =&gt; 'checkbox', 'name' =&gt; $name, 'id' =&gt; get_id_from_name($name, $value), 'value' =&gt; $value), _convert_options($options)); if ($checked) { $html_options['checked'] = 'checked'; } return tag('input', $html_options);
  • 向我们展示tag 函数,因为实际上您将name 分配给输入
  • function tag($name, $options = array(), $open = false) { if (!$name) { return ''; } return '&lt;'.$name._tag_options($options).(($open) ? '&gt;' : ' /&gt;'); }
  • 看来你的功能很多,我们也来看看_tag_options

标签: php symfony checkbox symfony1 symfony-1.4


【解决方案1】:

在对checkbox_tag() 函数一无所知的情况下,我只能建议将以下几行中的第一个参数更改为motif[]
&lt;?php echo checkbox_tag('motif', '1'); ?&gt;
&lt;?php echo checkbox_tag('motif', '2'); ?&gt;

输出仍将在motif 下,不带括号。如果该参数用于命名复选框,这会将行为更改为具有值的数组,而不仅仅是单个值。

【讨论】:

  • with motif[] 我没有恢复任何东西
  • 请给出checkbox_tag函数的定义。
  • 查看文档后,我自己提供的答案是正确的。看看:symfony-project.org/api/1_0/FormHelper#method_checkbox_tag
  • 我这样做了&lt;?php echo checkbox_tag('motif[]','1'); ?&gt;,但没有任何改变,我没有恢复任何东西。我选中了 2 复选框,但没有任何反应。它甚至不适合 if
  • 什么不适合if? if 语句应该保持不变。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-13
  • 2016-01-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多