Field Collection does the same (bad) thing that Inline Entity Form used to do:
field_collection_field_widget_embed_validate() validates the widget, and if no errors occurred, triggers submission:

  // Only if the form is being submitted, finish the collection entity and
  // prepare it for saving.
  if ($form_state['submitted'] && !form_get_errors()) {
    field_attach_submit('field_collection_item', $field_collection_item, $element, $form_state);

This means that the global submit code hasn't run yet, leading to potential problems due to mixing of the form processing phases.

This causes a direct incompatibility with IEF, cause IEF uses a #submit callback on the main form button to recursively process all IEF forms. Since you trigger submission inside validation, that code hasn't run yet, leading to some unprocessed data.

I think that generally it is a better approach to do what IEF 1.4 is doing: introduce a custom #element_submit key (#ief_element_submit is what IEF calls it), on parent form submit recursively call the element submit callbacks on all elements that have it. You can steal the code from IEF: http://drupalcode.org/project/inline_entity_form.git/commitdiff/a754ba7?...

Comments

rutzmoser’s picture

I may have run into this issue and not sure how to work around. I have multiple field collections so I disable the ajax (so it works...kind of) anyway when all required fields have valid values the add more button submits the form and takes the user back to the referring page. The mystery is when the form is submitted leaving one required field empty...a validation error is triggered THEN the add more button works as expected and the user can enter the required values and add as many field collections as needed. Any insight on how to work around what might be a different validation on the initial form build would be helpful.

daniel_j’s picture

The attached patch only triggers the submit if there is no error on the given form element, not on the form in general. I think this should help address this issue.