How to implement a multiple (AJAX) field collection with the FAPI Background: I have a field colleciton containing two fields. This field collection is attached to a profile entity and its number set to unlimited.

I am currently retrieving this field from the profile form to use it a custom form.

I get the form array and it is displayed correctly, but when I click on the button to add another element, I got a popup displaying this error:


  EntityMalformedException : Missing bundle property on entity of
  typefield_collection_item dans entity_extract_ids() (ligne 7663 dans
  /drupal_project/includes/common.inc).


Anyone have a clue or hint of what is going on behing the scene ? Maybe a solution to solve this issue ?  

Update: the form I am making is a ctools multistep form. I am opened to alternatives such as Dave Reid's multifield.
So, I followed the answer in the other thread Clive linked and this did the trick:

  $profile = new stdclass();
  $profile-&gt;type = 'some_profile_type'; 
  field_attach_form('profile2', $profile, $form, $form_state, LANGUAGE_NONE);


EDIT: Well, this is fixing the issue because it enables the form to use its widgets. But it remains a problem, the button part of the array is passed in form_state as a value, and I have to delete it manually...