I have a form:

$form['submit'] = array(
  '#type' => 'submit',
  '#value' => t('Sumbit'),

I need when this form is validated and submitted then show a ctools modal.

This is my hook_menu for the modal:

$items['thankyou/%ctools_js'] = array(
    'title' => 'Thank you',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'page callback' => 'thankyou_callback',
    'type' => MENU_CALLBACK,


The callback function:

function thankyou_callback($js = NULL) {
  // Content that we place in the popup.
  $popup_content = t('Thank you!');

  if (!$js) {
    return $popup_content;


  $output = array();
  $output[] = ctools_modal_command_display(t('Greetings'), $popup_content);

  print ajax_render($output);

My form submit:

function myform_submit($form, &$form_state) {
  // ...
  // show my modal here
  modal.show();  // ???

Then, How I show a ctools modal after form submit?

Please, with not ajax callback.

  • This isn't the complete answer but this thread should help you since this operation seems was fixed a couple of years back: drupal.org/node/1482968 Oct 27, 2015 at 3:01
  • Basically you should do an Ajax callback in your form submit I believe, there are examples of how the others did that in the thread posted above. Oct 27, 2015 at 3:02
  • @burnsjeremy thank you, but that thread not help me.
    – rpayanm
    Oct 27, 2015 at 18:36

1 Answer 1


You need call form to Popup by function ctools_modal_form_wrapper

Any error, message will show in popup, to check submit success you need use statement

if (!empty($form_state['executed'])) {
    $output[] = ajax_command_replace('#modal-content', 'Thank you');

Or you can use ajax form to call ajax.

$form['markup'] = array(
    '#markup' => '<div id="pop-up"></div>'
//You need markup for wrapper 
$form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Sumbit'),
    '#ajax' => array(
      'wrapper' => 'pop-up',
      'callback' => 'modal_form',

And function submit form

function modal_form($form, &$form_state) {
  //Process data when form submit
  $commands = array();
  $commands[] = ctools_modal_command_display('Form Submit', 'Say Thank You');
  print ajax_render($commands);

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.