Adding Drupal Field Collection element to a custom form
I'd like to add a Field Collection Item to my custom form. My form is a
custom event registration (will save data to Event Registration node), and
the field collection is available in Event Registration Content type. I
tried many codes and tries but none of them works.
module_load_include('inc', 'field_collection', 'field_collection.pages');
$field_collection_item = entity_create('field_collection_item',
array('field_name' => 'field_participant'));
$entity_form = field_collection_item_form($form, $form_state,
$field_collection_item);
$form['participant'] = $entity_form;
This loads the field collection item to my form, but I can't add another
Field collection item and the form other elements (company, phone, etc.)
is duplicated. I found another line that maybe should be add:
$field_collection_item->setHostEntity('node', $node);
but in that moment I haven't $node and I'm not sure it has to be.
No comments:
Post a Comment