symfony 2.3 form getData doesn't work in subforms collections

前端 未结 5 396
南方客
南方客 2021-01-31 23:04

I have a form which contains a collection. So I have:

/* my type */
public function buildForm(FormBuilderInterface $builder, array $options)
{
    $builder
             


        
5条回答
  •  遥遥无期
    2021-01-31 23:37

    In a submit or if you are editing, you can access the data when you turn the FormBuilder into a Form instance. And for a collection type you can try this:

    ...
    $form = $formBuilder->getForm();
    ...
    if ($this->getRestMethod() == 'POST') {
        $form->handleRequest($this->get('request'));
        if ($form->isValid()) {
            $formData = $form->getData();
            foreach ($formData['photos'] as $key => $collectionRow) {
                var_dump($collectionRow['photoname']);
                var_dump($collectionRow['size']);
            }
        }
    }
    

提交回复
热议问题