情况如下,我有一个表格:
public function buildForm(FormBuilderInterface $builder, array $options) {
foreach ($this->attributeGroupAttributes as $attribute) {
$builder->add('attribute-' . $attribute->getId(), $attribute->getType(), array(
'label' => $attribute->getName(),
));
}
}.
此表单用于验证动态添加到已提交的其他表单的数据。
这是我如何做的过程:
之后我通过以下方式将数据放入表单:
$form_validate->submit($normalizedData);
这是控制器:
public function createAction($formData) {
$itemService = $this->get('app.item');
$attributeGroupService = $this->get('app.attribute_group');
$attributeService = $this->get('app.attribute');
$attributeGroup = $attributeGroupService->getById($formData['attributeGroup']);
$attributeGroupAttributes = $attributeGroup->getAttributes();
$form_validate = $this->createForm(new \AppBundle\Form\ItemValidationType($attributeGroupAttributes));
$normalizedData = $itemService->normalizeDataForForm($formData);
$form_validate->submit($normalizedData);
if($form_validate->isValid()){
dump($form_validate->getData());
die();
}
die();
}
我得到的错误是:
-errors: array:1 [▼
0 => FormError {#855 ▼
-message: "The CSRF token is invalid. Please try to resubmit the form."
#messageTemplate: "The CSRF token is invalid. Please try to resubmit the form."
#messageParameters: []
#messagePluralization: null
-cause: null
-origin: Form {#836}
}
那种方式$ form_validate-> isValid()是假的。