I need to show a modal window on click from my mycustom.tpl.php

Here is my code in mycustom.tpl.php

<a href="/modal/nojs" class="ctools-use-modal ctools-use-modal-processed">False Positiv1e</a>

In my module file :

$items['modal/%ctools_js'] = array(
    'page callback' => 'modal_callback',
    'page arguments' => array(1),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,

 return $items;

function modal_callback($ajax) {

    $form_state = array(
      'ajax' => TRUE,
      'title' => t('MyModule Modal Form'),

    // Use ctools to generate ajax instructions for the browser to create
    // a form in a modal popup.
    $output = ctools_modal_form_wrapper('modal_form', $form_state);
    // If the form has been submitted, there may be additional instructions
    // such as dismissing the modal popup.
    if (!empty($form_state['ajax_commands'])) {
      $output = $form_state['ajax_commands'];

    // Return the ajax instructions to the browser via ajax_render().
    print ajax_render($output);

function modal_form($form, $form_state) {
  $form = array();

  $form['new_link_text'] = array(
    '#type' => 'textfield',
    '#title' => t('Link text'),

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

  return $form;

But when I am clicking on the button, Modal window Breaks and print $output array as below

enter image description here


You have to include below code in your mycustom.tpl.php also.

| improve this answer | |
  • I added it but still it is breaking – Akki Aug 23 '18 at 6:08
  • Have you cleared cache after adding this? – Ajay Reddy Aug 23 '18 at 6:24
  • Yes I added it in tpl also..but same result – Akki Aug 23 '18 at 6:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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