I haven't really tracked down what is causing this, but here's what I did:

Built the same form 3 times. The form contains a couple fields with field_attach, one description and one "tags" field. The 2nd form fails to submit with the following stack:

atal error: Cannot unset string offsets in /Users/jacob/work/drupal-7/modules/field/field.default.inc on line 23 Call Stack: 0.0001 66224 1. {main}() /Users/jacob/work/drupal-7/index.php:0 0.0952 2506780 2. menu_execute_active_handler() /Users/jacob/work/drupal-7/index.php:22 0.0975 2612256 3. call_user_func_array() /Users/jacob/work/drupal-7/includes/menu.inc:476 0.0975 2612548 4. media_page_multiedit() /Users/jacob/work/drupal-7/includes/menu.inc:0 0.0975 2613928 5. call_user_func_array() /Users/jacob/work/drupal-7/sites/all/modules/d7_modules/media/media.pages.inc:56 0.0975 2614308 6. multiform_get_form() /Users/jacob/work/drupal-7/sites/all/modules/d7_modules/media/media.pages.inc:0 0.1337 2895096 7. drupal_build_form() /Users/jacob/work/drupal-7/sites/all/modules/d7_modules/multiform/multiform.module:91 0.1436 3072496 8. drupal_process_form() /Users/jacob/work/drupal-7/includes/form.inc:331 0.1459 3112048 9. form_execute_handlers() /Users/jacob/work/drupal-7/includes/form.inc:753 0.1459 3115004 10. media_edit_submit() /Users/jacob/work/drupal-7/includes/form.inc:1167 0.1476 3115568 11. field_attach_submit() /Users/jacob/work/drupal-7/sites/all/modules/d7_modules/media/media.pages.inc:418 0.1476 3117844 12. _field_invoke_default() /Users/jacob/work/drupal-7/modules/field/field.attach.inc:827 0.1476 3118436 13. _field_invoke() /Users/jacob/work/drupal-7/modules/field/field.attach.inc:371 0.1478 3123604 14. field_default_extract_form_values() /Users/jacob/work/drupal-7/modules/field/field.attach.inc:199

Basically, $form_state['values']['tags']['value'][LANGUAGE] should be an array, and it is for the first form, but on the 2nd form, it is an empty string. This causes a bad unset to be called in the function mentioned above which craps it out.

If I remove the tags field, it works fine. Also, if the first form has no tags field, but the 2nd one has one, it also fails (so not about the same named variable).

Comments

chx’s picture

Is there some JS problem? What's $_POST when submitting the multiform?

JacobSingh’s picture

Seems like it's not client side. When the tags field is in the first form, it looks the same as the 2nd form

[field_tags] => Array
                        (
                            [und] => 
                        )

But I guess when in the first form, it is transformed to being an array of values like expected, and on the 2nd it isn't...

JacobSingh’s picture

yeah, form_state['values'] on the 2nd one doesn't end up with an array in that field, but $_POST is fine. Well, I'm guessing the tags field code transforms it from an empty string (or a comma delimited string really) into the array and multiform breaks it for the 2nd form...

digging...

JacobSingh’s picture

yeah, would appear that taxonomy_autocomplete_validate() doesn't get called when in the 2nd form...

JacobSingh’s picture

Ah, I think the problem is if the form_id of the first from and the 2nd form are the same:

function drupal_validate_form($form_id, &$form, &$form_state) {
  $validated_forms = &drupal_static(__FUNCTION__, array());

  if (isset($validated_forms[$form_id]) && empty($form_state['must_validate'])) {
    return;
  }

The if stmt there will return true, so we don't validate the 2nd one. Not sure yet what the best approach is here, confirming, but I'm pretty sure this is it.

JacobSingh’s picture

Title: If 2nd form contains taxonomy "tags" field, field_attach_submit fails » If the same form_id is used twice, validate doesn't run the 2nd time.
Priority: Normal » Critical
Status: Active » Needs review
StatusFileSize
new760 bytes

Something tells me this will not be the end of this issue, but it fixes the problem for me.

chx’s picture

Status: Needs review » Closed (won't fix)

#766146: Support multiple forms with same $form_id on the same page implement hook_forms and use different form ids.