I have a small custom form which has its own submit button.

$form['activity']['submit'] = array(
      '#type' => 'button',
      '#value' => t('Execute'),
      '#name' => 'test_button',
      '#submit' => array('my_custom_form_submit')
    );

I have place this in the page manager in the node edit form.

But the problem is the function my_custom_form_submit is not get executed. Instead the node form gets submitted and redirected to node view page.

And when I try to add my custom form to the node form using form_alter

case 'activity_node_form':
      $id = 'glue_site_activity_participants_form';
      $form['activity'] = drupal_get_form($id);
break;

The my custom form submit buttons works but the node form submit button also executes my custom form submit function.

Is there any way to to execute my custom submit function on clicking on the custom form submit button and executes node form submit on clicking the node submit button?

Comments

edward.radau’s picture

I think one of the main issues you're running into is that you're appending your custom form to the existing node edit form. They will share the same submission handlers. One thing you could try is in your custom form for the submit button, try to explicitly define the submission function for your custom form by assigning a #submit to it instead of having Drupal assume what it is. Haven't tried what you're doing but it's worth a shot.

Another possibility if that doesn't work is maybe try to override the theme for this node type's edit page by creating a page--node-edit-type.tpl.php. And then you could embed your form within there.

hmdnawaz’s picture

I have tried this. As you can see my code above. I have separately mentioned the submit handler for my custom form submit button.
But still it does not work.

Ahmad Nawaz
Acquia Certified Developer
Email: hmdnawaz@gmail.com
Skype: hmdnawaz

Jaypan’s picture

You can't embed a form in another form. What you can do is:

* Add your form elements to the existing form using hook_form_alter()
* Handle the submission of your form elements in hook_node_insert() and hook_node_update() OR
- Add a custom submit handler to the existing form, and handle your submission after the node form has done its stuff.