Symfony2 Form - How to create a parent with a hidden field

I am new to Symfony forms and trying to figure out how to create a form with a hidden field that references the parent. For example, I have a list that has many-to-one relationships with contacts. When creating a new contact, he needs a hidden field with the identifier of the list to which the contact is added.

I am currently trying to embed a form ListIdTypein my form ContactType. The only field on the form ListIdTypeis the list identifier. This works well, because I can set the list to an empty communication object, and it will automatically populate the element in the form with the name contact[list][id](which is defined in the form ListIdType). The problem is that when I submit the form, I get an error that no element "id" or methed "setId ()" exists in the list class.

But I feel like I'm doing something wrong, but I can’t find the documentation to point me in the right direction.

+5
source share
2 answers

, , property_path, FALSE. ContactType::buildForm:

  $builder->add('list_id', 'hidden', array(
        'data' => $data->getList()->getId(),
        'property_path' => FALSE,
    ));

.

, . , - !

+6

Gregwar Forum bundle, entity_id. , .

https://github.com/Gregwar/FormBundle

+3

All Articles