donglu3243 2014-12-08 07:50
浏览 53

为什么在Symfony2表单中需要字段

Can someone tell me why in form I have a filed that is required:

<input type="checkbox" id="client_invoice" name="client[invoice]" class="invoice-controller" value="1" required="required">

if in Entity I set:

/**
 * @ORM\Column(type="boolean", nullable=true)
 *
 * @var boolean
 */
protected $invoice;

My gues is becouse in form builder I have:

$builder->add('invoice', 'checkbox', array('label' => 'form.client.invoice'));

and then 'required' value is automatically set to true (becouse of the 3rd parameter in add function). Am I right, or is there another reason that this field is required?

  • 写回答

1条回答 默认 最新

  • douyaosi3164 2014-12-08 08:00
    关注

    Form fields are required by default in Symfony2. You can turn it off for a specified form field by:

    $builder->add('invoice', 'checkbox', array(
        'label' => 'form.client.invoice',
        'required' => false,
    ));
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器