I'm trying to add the AJAX throbber in core to a form submit button, specifically the Private Message module new message page.

Here is my code:

function MYMODULE_form_privatemsg_new_alter(&$form, &$form_state, $form_id) {
  $form['actions']['submit']['#ajax'] = array(
'callback' => 'MYMODULE_submit_throbber_callback',

function MYMODULE_submit_throbber_callback($form, $form_state) {

Here's what I have done so far.

First, I looked at the Page Throbber module for ideas, but this does everything in hook_init(), and it doesn't use the throbber included in core. If possible, I want to avoid replicating what is already in core for a single form.

Next, I looked in the Examples module, specifically the AJAX example that includes an AJAX submit example. However, this is for adding a callback to do something else, but all I want to do is get the pager, which appears to happen automatically if you add any kind of callback.

So I added a dummy callback that just returns. This gives me a throbber, but it breaks the submit functionality of the form. How do I get the throbber without breaking the form submit?


2 Answers 2


It should be easily done like this:

$form['submit']['#ajax'] = [
  'callback' => 'MYMODULE_submit_throbber_callback',
  'progress' => [
    'type' => 'throbber',
    'message' => NULL,

And then return $form in the callback;


If you want to show a throbber on the submit button without coding, you can use the Hide Submit module.

My question is about doing it programatically, but I'm listing this as an answer for people who don't want to code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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