0
這裏是我的形式上市:Symfony2的額外領域FormError與隱藏字段驗證表單
$builder = $this->createFormBuilder($project)
->add('name','text')
->add('type','choice', array(
'choices' => $enumtype
))
->add('begindate','date')
->add('expecteddate','date')
->add('events', 'collection', array(
'type' => new EventType(),
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
))
->add('financial', 'file', array(
'property_path' => false,
'required' => false
))
->add('investition', 'file', array(
'property_path' => false,
'required' => false
));
if ($defaults) {
$builder->add('id','hidden',array('data' => $defaults['id'], 'property_path' => false));
$form = $builder->getForm();
$form->setData($defaults);
}
else
$form = $builder->getForm();
當我試圖驗證這種形式,我收到FormError對象:
Array (
[0] => Symfony\Component\Form\FormError Object (
[messageTemplate:protected] => This form should not contain extra fields.
[messageParameters:protected] => Array (
[{{ extra_fields }}] => id
)
[messagePluralization:protected] =>
)
)
如果我排除「ID」字段 - 一切正常。 我如何使用隱藏類型並進行驗證?
詢問時設置你做了同樣的FormType類還是你綁定到一個實體?如果是後者,可能性是綁定到未定義的屬性(id),或者它是不能以這種方式在窗體中設置的主鍵。 – phpisuber01
我將它綁定到一個實體,但這是未定義的屬性。名稱無關緊要。 – Aronsky