I'm having issues calling an existing form from the commerce_coupon module which runs a default submit handler callback (commerce_coupon_form_submit).
My form builds off of that form and simply tries to replace the default '#submit' value to call my own submit function instead of the default commerce_coupon one. I'm using drupal_get_form so my code looks like the following:
$form = drupal_get_form('commerce_coupon_form', $coupon);
$form['#submit'] = array('mymodule_coupon_submit');
return drupal_render($form);
That is the code from inside a function that is supposed to return the rendered form. The problem is the default commerce_coupon_form_submit submit handler is still running and my own function doesn't get called. I think this has something to do with the form_id or form_state still being commerce_coupon_form.
I've found related problems on stackexchange but responses were directed for other versions of Drupal. I'm using D7 so please bear that in mind.
I'm adding a little more detail that may help get a better answer for this. The original commerce_coupon_form seems to try to use a button-level #submit handler as there is the following before the form is returned:
$form['actions'] = array(
'#type' => 'container',
'#attributes' => array('class' => array('form-actions')),
'#weight' => 400,
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Save coupon'),
'#weight' => 40,
);
but the actual #submit handler isn't assigned so the default drupal handler is being set at the root of the form. I've tried assigning a button-level submit and overriding the root drupal assigned submit to a blank array but that doesn't seem to work. I'm trying to track down documentation for drupal or the function that sets the default #submit so I can figure this out. If you can point me in the right direction I would appreciate it.
print_r($form['#sumbit'])
after you assign it your fuction. has it only one element of array?