Multiple Ajax submit, same Form ID I have a page with a table of nodes each one with it's own submit button. When pressed the button should call a custom ajax function which creates a cookie with the corresponding orm ID as its value. 

My code:

function custom_cart_form_alter(&amp;$form,&amp;$form_state,$form_id){      
    if ((stristr($form['#form_id'], 'uc_product_add_to_cart_form')) != FALSE){                      
        $form['#submit'][] = 'set_custom_cookie';
    }

    return $form;
}

function set_custom_cookie($form, &amp;$form_state){
    user_cookie_save(array($form['#form_id'] =&gt; TRUE));     
}


However, when the set_custom_cookie() function is called it receives the last value of $form['#form_id'] and not the ID of the corresponding form.

To clear things up: if I add the following at the end of hook_form_alter() :

function custom_cart_form_alter(&amp;$form,&amp;$form_state,$form_id){      
    if ((stristr($form['#form_id'], 'uc_product_add_to_cart_form')) != FALSE){                      
        $form['#submit'][] = 'set_custom_cookie';
    }

    $form['#form_id'] = "test123";  //Added this line to demonstrate the issue
    return $form;
} 


then function set_custom_cookie() will receive "test123" on call as the value of $form['#form_id'].

How can I make set_custom_cookie() receive the corresponding form ID?

I'm using Drupal 7.
You should be able to get the form id from the $form_state variable as $form_state['build_info']['form_id'] inside your submit handler.