I have made a modal form using ctools. The form works okay when the user has access rights, but with no access rights an empty modal form is showing and I get a browser error saying

"An AJAX HTTP error occurred. HTTP Result Code 403" (and a lot of debugging information)

Is this a flaw in ctools modal or am I missing something?

In case of access denied I would like to fall back to a standard access denied message.

  • I now know that the error is displayed by Drupal.ajaxError in drupal.js. So I am guessing that ctools modal.js should try to do some error handling itself if at all possible.
    – Dawied
    Commented Nov 5, 2013 at 14:16
  • You can also check user permission in your code. Commented Nov 6, 2013 at 10:13
  • I think that in reality this situation would never occur because the link would not exists. Still the user could type in a invalid url using the ajax suffix and get this error.
    – Dawied
    Commented Nov 8, 2013 at 9:12

1 Answer 1


I will try to answer this myself. There is no mentioning of this issue in the CTools project itself but the issue is mentioned at the CTools Auto-modal project https://drupal.org/node/1450232

There is also a solution:

  • implement hook_page_delivery_callback_alter
  • check if callback is made by one of your ajax links
  • if so, check is user has access by using menu_get_item and inspecting the resulting router item
  • if access is ok, do nothing
  • if access denied or page not found, render a message

The solution at CTools Auto-modal renders the message in the CTools modal box. But I preferred to kill the CTools modal and just do nothing:

$commands[] = ctools_modal_command_dismiss();
print ajax_render($commands);

This way the dreaded drupal ajax error will never appear.

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.