为什么需要 Symfony2 形式的 fiels


Why fiels is required in Symfony2 form

有人可以告诉我为什么在表格中我有一个必需的文件:

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

如果在实体 I 中设置:

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

我的 gues 是我拥有的表单构建器中的:

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

然后"必需"值自动设置为 true(在 Add 函数中使用第 3 个参数)。我是对的,还是有其他原因需要此字段?

表单字段在 Symfony2 中默认为必填字段。您可以通过以下方式为指定的表单域关闭它:

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