I’m trying to save a node (with the normal node form) via an ajax callback. The first save works. But after that I want to return the same node form again so that the user can update the values and save the node again. But this second save attempt fails. I always get a message like “this form has already been submitted”. Are any solutions for this problem? Or shall I write a custom JS menu hook which saves the node programmatically?
Here are the relevant parts of my module
function MYMODULE_form_finding_node_form_alter (&$form, &$form_state){ $form['#prefix'] = '<div id="wrapper">'; $form['#suffix'] = '</div>'; $form['actions']['submit']['#ajax'] = array( 'callback' => 'MYMODULE_finding_node_form_submit_ajax', 'wrapper' => 'finding-form-wrapper' ); } function MYMODULE_finding_node_form_submit_ajax($form, &$form_state){ $form_id = '#' . str_replace('_','-',$form['#form_id']); $commands = array(); $commands[] = ajax_command_remove('.l-messages'); if(form_get_errors()){ $commands[] = ajax_command_replace($form_id, '<div id="finding-form-wrapper"></div>'); $commands[] = ajax_command_replace('#finding-form-wrapper', drupal_render($form)); } else{ $node = $form_state['node']; $form_state = array(); $form_state['rebuild'] = TRUE; $form_state['build_info']['args'] = array($node); $form = drupal_build_form('finding_node_form', $form_state); $form['#id'] = str_replace("_", "-", $form_id); $commands[] = ajax_command_replace($form['#id'], drupal_render($form)); } $commands[] = ajax_command_prepend('.page', '<section class="l-messages row"><div class="columns">' . theme('status_messages') . '</div></section>'); return array('#type' => 'ajax', '#commands' => $commands); }