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(&$form, $form_state, $form_id) {
$form['actions']['gaylord_submit'] = array(
'#type' => 'submit',
'#value' => t('Add Gaylord'),
'#submit' => array('inventory_stocking_ticket_form_gaylord_submit'),
'#executes_submit_callback' => TRUE,
'#name' => 'edit-gaylord-submit',
'#limit_validation_errors' => array(),
);
function inventory_stocking_ticket_form_gaylord_submit(&$form, &$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 & there are no unlimited cardinality fields, everything works great, node is created or modified, form values are saved, & my custom submit handler stuff is performed. If, however, I have a field with unlimited cardinality & 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
& 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, & 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 & 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 & 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.