How to handle multiple forms' submission in a custom module by clicking on a link I have 2 forms in my custom drupal7 module.
The 1st one (mymodule_form1_form) is a normal form with a lot of fields and a submit button at the bottom.
The 2nd one (mymodule_delete_data_form) has 1 hidden field and there is no submit button.
There is a link at the end of the 1st form which triggers a javascript logic. The javascript logic submits the 2nd form.

My problem is that I can't catch the submission of the 2nd form. The page reloads, but it doesn't entry into the mymodule_delete_data_form_submit function and I can't run the special business logic that removes the data from the database in this case.

The 1st form

function mymodule_form1_form($form, &amp;$form_state, $node, $cid)
{
    $form['field1'] = array(
        '#type'       =&gt; 'textfield',
        '#title'      =&gt; 'Name',
        '#title_display'  =&gt; 'invisible',
        '#size'       =&gt; 60,
        '#maxlength'  =&gt; 128,
        '#required'   =&gt; TRUE,
        '#attributes' =&gt; array(
            'placeholder' =&gt; 'Name',
        )
    );

    $form['delete_record_link'] = array(
        '#markup'     =&gt;
            "&lt;div class='delete-record'&gt;
                &lt;a href='#' onclick='return false;'&gt;I would like to delete my record...&lt;/a&gt;
            &lt;/div&gt;",
        '#attributes' =&gt; array(
            'class'   =&gt; array('additional')
        )
    );

    $form['submit'] = array(
        '#type'  =&gt; 'submit',
        '#title' =&gt; filter_xss("Submit"),
        '#value' =&gt; "Submit",
        '#title_display' =&gt; 'invisible'
    );

    return $form;
}


The 2nd form

function mymodule_delete_data_form($form, &amp;$form_state, $node, $cid)
{
    $form['#submit'][] = 'mymodule_delete_data_form_submit';

    $form['delete_record'] = array(
        '#type' =&gt; 'textfield',
        '#title' =&gt; 'Remove the data from the database',
        '#title_display' =&gt; 'invisible',
        '#size' =&gt; 60,
        '#maxlength' =&gt; 128,
        '#attributes' =&gt; array(
            'placeholder' =&gt; 'Remove the data from the database',
        ),
        '#value' =&gt; "0"
    );

    return $form;
}


The submit function of the 1st form (it works like a charm):

function mymodule_form1_form_submit($form, &amp;$form_state)
{
    echo "submit function 1&lt;br/&gt;";
    exit();
}


The submit function of the 2nd form (it doesn't trigger):

function mymodule_delete_data_form_submit($form, &amp;$form_state)
{
    echo "submit function 2&lt;br/&gt;";
    exit();
}


The javascript logic that submits the 2nd form, when you click on the link in the 1st form:

jQuery(function() {
    var delete_record_field = jQuery("#edit-delete-record");
    var delete_record_link  = jQuery("#mymodule-form1-form .delete-record a");

    delete_record_link.on("click", function() {
        // set the value of the hidden field to 1
        delete_record_field.val("1");

        // submit the form
        jQuery("#mymodule-delete-data-form").submit();
    });
});


What is wrong in my code? How can I catch the submission of the 2nd form?
Drupal requires a submit button to submit - it uses the value of the submit button to determine which form was submitted.

Add a submit button to your form, and instead of executing $.submit() on your form, execute $.mousedown() on the hidden submit button.