I have a form which consists of one submit button (Add to cart). I made it submit via AJAX but the problem is that when I press the button the second or third (and so on) times, the submit handler doesn't execute. I think this happens because the form_build_id and form_token fields should be rebuilt.
Do you have any idea on how I can achieve this functionality?
This is the code I am using.
function mymodule_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'my_form_id') {
$form['submit']['#ajax'] = array(
'callback' => 'mymodule_ajax_form_callback',
'wrapper' => 'my_form_wrapper',
);
$form['#prefix'] = '<div id="my_form_wrapper">';
$form['#suffix'] = '</div>';
}
}
function mymodule_ajax_form_callback($form, &$form_state){
return $form;
}
$form['submit']['#ajax'] = array();
The ajax callback is a function which returns an ajax command