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.

  • 2
    Can you show your code please? Very hard to debug code without seeing code
    – Clive
    Aug 29, 2013 at 16:12
  • Form API does not work well with full-blown fields... to bad I don't know anything better
    – Mołot
    Aug 29, 2013 at 21:16
  • There is not much to be shown, it is just a profile form retrieved with drupal_get_form('user_register_form'). Then the field collection contains two term reference, but this is configured in the UI.
    – B2F
    Aug 30, 2013 at 9:47
  • It must be a problem around field_attach_form_validate as the entity parameter is null, Surely got to override some handler/validation.
    – B2F
    Aug 30, 2013 at 12:21
  • So I switched to multifield, because the overhead of field collection is quite hard to comprehend. Now I only got a problem when I need to dynamically add a field item to the multifield. Seems like it is because I am creating a multistep form with ctools and the form_state array isn't likely to be understood by field_form_get_state in field_add_more_js.
    – B2F
    Aug 30, 2013 at 13:58

1 Answer 1


So, I followed the answer in the other thread Clive linked and this did the trick:

  $profile = new stdclass();
  $profile->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...

  • That's not exactly Form API - please either edit question title or include some words of explanation why it's good to choose different approach.
    – Mołot
    Sep 2, 2013 at 11:51
  • yes you are right, although this is working, I will unmark it as accepted, so this stays opened if somebody find a better answer.
    – B2F
    Sep 2, 2013 at 13:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.