AJAX / AHAH 'Add More' Button on Unlimited Cardinality Fields Conflicts with Custom Submit Handler I have a node add form with some integer text fields that have unlimited cardinality, which causes an AJAX 'Add More' button to be displayed for those fields. The form also has a custom submit handler that is defined in a custom module.

  function formalter_form_alter(&amp;$form, $form_state, $form_id) {

$form['actions']['gaylord_submit'] = array(
  '#type' =&gt; 'submit',
  '#value' =&gt; t('Add Gaylord'),
  '#submit' =&gt; array('inventory_stocking_ticket_form_gaylord_submit'),
  '#executes_submit_callback' =&gt; TRUE,
  '#name' =&gt; 'edit-gaylord-submit',
  '#limit_validation_errors' =&gt; array(),
);

function inventory_stocking_ticket_form_gaylord_submit(&amp;$form, &amp;$form_state) {
if ($form_state['clicked_button']['#id'] == 'edit-gaylord-submit') {
  node_form_submit($form, $form_state);

//do custom stuff here

}
}


Here's my problem: If the custom submit handler function is defined inside the hook_form_alter function &amp; there are no unlimited cardinality fields, everything works great, node is created or modified, form values are saved, &amp; my custom submit handler stuff is performed. If, however, I have a field with unlimited cardinality &amp; my custom submit handler function is defined inside the hook_form_alter function, I receive an error: PHP Fatal error:  Call to undefined function inventory_stocking_ticket_form_gaylord_submit() in /hosting/somesite/com/htdocs/cms_sandbox/includes/form.inc on line 1464 &amp; a white screen of death. If I move the custom submit handler function outside of the hook_form_alter, there's no error even with unlimited cardinality fields, the node is created or modified, &amp; my custom submit handler stuff works, but field values are not saved.

I've further discovered that commenting out the code that creates the AJAX 'Add Another' button in core's field.form.inc makes everything work, even with the submit handler inside the hook_alter &amp; unlimited cardinality fields. Of course there's no 'Add Another' button now, defeating the purpose of having unlimited fields.

I have two questions:


What is causing the conflict &amp; PHP error when the submit handler inside the hook_form_alter is combined with unlimited cardinality fields?
Why won't the custom submit handler save field data when it is defined outside of the hook_form_alter?


If I could solve either of these problems I'd have what I needed. Any help is hugely appreciated.
try this:

function formalter_form_alter(&amp;$form, $form_state, $form_id) {
  // override the default submit
  $form['#submit'] = array('inventory_stocking_ticket_form_gaylord_submit');
  // include the default submit and your custom submit
  //$form['#submit'][] = 'inventory_stocking_ticket_form_gaylord_submit';
}

function inventory_stocking_ticket_form_gaylord_submit(&amp;$form, &amp;$form_state) {
  if ($form_state['clicked_button']['#id'] == 'edit-gaylord-submit') {
    node_form_submit($form, $form_state);

    //do custom stuff here

  }
}