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,
    ));
    
    评论

报告相同问题?

悬赏问题

  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题