I have a complex form of two logical parts, which I have placed in different functions (my_module_partner_form
& my_module_fields_form
). Both forms have submit handlers (my_module_partner_form
- 1 submit, my_module_fields_form
- 2 different submits). I would like to display those on one page.
So my solution was the following:
Create a menu item like the following:
$items['complex-form/%/%/%'] = array(
'title' => 'Complex Form',
'page callback' => 'drupal_get_form',
'page arguments' => array('my_module_complex_form', 1, 2, 3),
'access callback' => 'my_module_complex_form_custom_access',
'access arguments' => array(1, 2, 3),
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/some_file.inc',
);
Create a callback function to handle it
function my_module_complex_form($form, &$form_state, $param1, $param2, $param3)
{
// ... some irrelevant code here ...
$form = array();
$form = drupal_get_form('my_module_partner_form', $someParam);
$form += drupal_get_form('my_module_fields_form', $someParam);
return $form;
}
Here are the forms itself (code obfuscated)
function my_module_fields_form($form, &$form_state, $param1)
{
// ... some irrelevant code here ...
$form['save_all'] = array(
'#type' => 'submit',
'#value' => 'Update',
);
$form['save_with_no_changes'] = array(
'#type' => 'submit',
'#value' => 'Save with no changes',
);
return $form;
}
function my_module_partner_form($form, &$form_state, $param1)
{
// ... some irrelevant code here ...
$form['save_profile'] = array(
'#type' => 'submit',
'#value' => 'Save contact details',
);
return $form;
}
SO, the question is: what am I missing, as the submit function for each of the functions (except for the my_module_complex_form_submit
- why?) is being called, but I can not identify which button was clicked.
What I have already tried, not to waist your time:
- reading
$form_state['clicked_button']['#value']
- always the same - "Update". - creating custom
#submit
elements for each button - this will not work as I only need one handler to work each time. Please correct me if I missed smth in the workflow.
Any ideas welcome.