How to clear already rendered "drupal messages" after successful ajax submit? Possible Duplicate:
  Remove tabledrag statuses on Ajax submit and display status message after Ajax submit  




I have a custom form which saves "weights" of nodes to a custom table. The form has an Ajax submit handler. The form is rendered in a table using theme('table') and it has draggable handles added using drupal_add_dragtable.

Because the form gets submitted via Ajax, the messages such as "Changes made in this table will not be saved until the form is submitted" and any other messages in the "message region" don't get cleared even if the form is submitted and the values are saved.

How do I clear this message area? Or is there a way to hook into the "success" function of the Ajax? Or is it at all possible to run a custom javascript function after the form is submitted via Ajax? Any one of these possibilities will do for me. Please advise.



I've partially succeeded in solving this by returning an array of ajax commands from my callback function.

In particular I return the following commands:

$commands = array();
$commands[] = ajax_command_html('#page-banners-status', theme('status_messages'));
$commands[] = ajax_command_remove('.tabledrag-changed');
$commands[] = ajax_command_remove('.tabledrag-changed-warning');


but I've run into a new problem where now, even though the "Changes made in this table will not be saved until the form is submitted" message is removed after the save, it doesn't come back if the table is further modified after the save. I've tried to grab the form again and pass it back using an ajax command:

// my form function receives additional parameters
$form = drupal_get_form('my_custom_form', $path, $tid);
$commands[] = ajax_command_html('.table-container', drupal_render($form));


But whenever I call drupal_get_form from the callback function, it seems to break the function.
You can do it in two ways,

First One,

function hook_preprocess_page(&amp;$vars) {
  //if(CHECK FOR THE FORM PAGE)
  $vars['show_messages'] = 0;
  $_SESSION['messages'] = '';
  // END IF
}


Second One is

at the end of the form submit callback write the code like below

unset($_SESSION['messages'])


or

$_SESSION['messages'] = '';