0

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.

marked as duplicate by kiamlaluno May 2 '12 at 11:03

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

You can do it in two ways,

First One,

function hook_preprocess_page(&$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'] = '';
  • wouldn't this "Prevent" messages from displaying instead of "removing old" messages? I don't want to prevent messages from displaying. – Beebee Mar 1 '12 at 15:51
  • It would not prevent it will only flush out already set messages. – GoodSp33d Apr 1 '12 at 11:22
  • 2
    drupal_get_messages() would do the trick anyway – Pan Chrono Feb 20 '13 at 14:14
  • $_SESSION['messages'] = '' inside the validate function will do the job. Thanks for showing the path – augusto May 4 '17 at 20:01

Not the answer you're looking for? Browse other questions tagged or ask your own question.