AJAX error when ctools_modal_command_dismiss() is called So I'm having a problem with dismissing a Ctools modal within a form submit's callback function. Once I have processed any submit data, I'd like to dismiss the modal without redirecting the page (easy enough), but each time I click the submit button with ctools_modal_command_dismiss() included in the callback function, I'm presented with an AJAX error such as below:

An AJAX HTTP error occurred. HTTP Result Code: 200 Debugging information follows.

I'm stumped as to why this is happening. The modal works perfectly without the dismiss function.

function pay_rise_menu() {
  $items = array();
  $items['pay_rise/%ctools_js'] = array(
    'page callback' =&gt; 'pay_rise_modal_email_share',
    'page arguments' =&gt; array(1),
    'access arguments' =&gt; array('access content'),
  );

  return $items;
}

function pay_rise_modal_email_share($ajax) {
  if ($ajax) {
    ctools_include('ajax');
    ctools_include('modal');

    $form_state = array(
      'ajax' =&gt; TRUE,
      'title' =&gt; t('Share by email'),
    );

    $output = ctools_modal_form_wrapper('pay_rise_modal_email_share_form', $form_state);

    if (!empty($form_state['ajax_commands'])) {
      $output = $form_state['ajax_commands'];
    }

    print ajax_render($output);
    drupal_exit();
  }
  else {
    return drupal_get_form('pay_rise_modal_email_share_form');
  }
}

function pay_rise_modal_email_share_form($form, &amp;$form_state) {
  $form = array();

  $form['recipient'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Recipient'),
    '#attributes' =&gt; array(
      'placeholder' =&gt; 'Recipient email...',
    ),
  );

  $form['body'] = array(
    '#type' =&gt; 'textfield',
    '#title' =&gt; t('Message'),
    '#attributes' =&gt; array(
      'placeholder' =&gt; 'Message...',
    ),
  );

  $form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
    '#ajax' =&gt; array(
      'callback' =&gt; 'pay_rise_modal_email_share_form_callback',
    ),
  );

  return $form;
}

function pay_rise_modal_email_share_form_callback($form, &amp;$form_state) {
  $values['message'] = $form_state['values']['body'];
  drupal_mail('pay_rise', 'share', $form_state['values']['recipient'], 'en', array('values' =&gt; $values));
  $form_state['ajax_commands'] = ctools_modal_command_dismiss('Thanks. Your message has been sent.');
}


The above is invoked once the following link is clicked:

l('email', 'pay_rise/nojs', array('attributes' =&gt; array('class' =&gt; 'ctools-use-modal icon-mail')))
You are doing it wrong, ctools modal works a little bit different. Better do it like this:

remove #ajax property from form submit button, let it work as usual:

...
$form['submit'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Submit'),
  );
...


define submit callback as usual:

function pay_rise_modal_email_share_form_submit($form, &amp;$form_state) {
  $values['message'] = $form_state['values']['body'];
  drupal_mail('pay_rise', 'share', $form_state['values']['recipient'], 'en', array('values' =&gt; $values));
}


build modal callback:

function myCallback($js = NULL) {
  if (!$js) {
    drupal_access_denied();
    drupal_exit();
  }

  ctools_include('modal');
  ctools_include('ajax');

  $form_state = array(
    'title' =&gt; t('My modal title'),
    'ajax' =&gt; TRUE,
    'build_info' =&gt; array(
      'args' =&gt; array(),
    ),
  );

  $commands = ctools_modal_form_wrapper('pay_rise_modal_email_share_form', $form_state);

  if (!empty($form_state['executed'])) {
    $commands = array();
    $commands[] = ctools_modal_command_dismiss();
  }

  print ajax_render($commands);
  drupal_exit();
}


ctools itself handles ajax submission.. That's it.