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' => 'pay_rise_modal_email_share',
'page arguments' => array(1),
'access arguments' => array('access content'),
);
return $items;
}
function pay_rise_modal_email_share($ajax) {
if ($ajax) {
ctools_include('ajax');
ctools_include('modal');
$form_state = array(
'ajax' => TRUE,
'title' => 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, &$form_state) {
$form = array();
$form['recipient'] = array(
'#type' => 'textfield',
'#title' => t('Recipient'),
'#attributes' => array(
'placeholder' => 'Recipient email...',
),
);
$form['body'] = array(
'#type' => 'textfield',
'#title' => t('Message'),
'#attributes' => array(
'placeholder' => 'Message...',
),
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
'#ajax' => array(
'callback' => 'pay_rise_modal_email_share_form_callback',
),
);
return $form;
}
function pay_rise_modal_email_share_form_callback($form, &$form_state) {
$values['message'] = $form_state['values']['body'];
drupal_mail('pay_rise', 'share', $form_state['values']['recipient'], 'en', array('values' => $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' => array('class' => 'ctools-use-modal icon-mail')))