How to implement popups using ctools modal forms in your Drupal 7 site

These are the steps below to implement the pop-ups

First we need to install Chaos tools module which contains the code for the popup.

Next we need to identify the links and buttons on which we need to trigger the popup. Once we have identified the links we need to define those links using hook_menu.

The page callback function of the menu definition would need to be created as per the following code. As it is a callback function you can give a suitable name respect the namespace of your site.

/**
   * Custom  Page callback
   *
   */
  function custom_modal_callback() {
    ctools_include('ajax');
    ctools_include('modal');
    $form_state = array(
      'ajax' => TRUE,
      'title' => 'Title',
    );

    $output = ctools_modal_form_wrapper('custon_modal_form', $form_state);
    print ajax_render($output);
    drupal_exit();
  }

 
  

Once we have defined the callback then we would need to add the 'class ctools-use-modal' class for the link or button where we need to attach our modal dialog.

As we used the Drupal l() function to generate the relevant links and added the class to the link using that function as shown below.

l('click me', 'modal/link', array( 'attributes' => 
array('class' => array( 'ctools-use-modal' )) ));

 
  


Code explanation :

ctools_include is used to include the two required parameters for defining the pop-up. The title will show as the title of the pop-up. If you have already defined a form elsewhere and would like to include it in the pop-up you can call it here using ctools_modal_form_wrapper.



Ankur Pratap Singh

Experienced Project & Operations Manager | Open for Freelance work

8 年

Good.

要查看或添加评论,请登录

Rohit Kumar Jha的更多文章

  • Drupal’s Default Robots.txt File

    Drupal’s Default Robots.txt File

    This article was originally written on 2010-09-17 but has been updated with current information and SEO best practices.…

  • Enhance Drupal Performance

    Enhance Drupal Performance

    A Drupal website that is well-optimized for performance can handle several million visits each day. There are several…

  • S3 Bucket Configuration With Drupal8

    S3 Bucket Configuration With Drupal8

    Requirements: 1. Amazon S3 bucket https://aws.

  • Update Drupal 8 Via 5 Drush command

    Update Drupal 8 Via 5 Drush command

    Steps to update Drupal 8 core using Drush 8.x.

  • How To Deal With Politics At Work Place?

    How To Deal With Politics At Work Place?

    You should never shy from politics. If you are on planet earth, living with people in cities, in villages, there are…

  • How to Audit Drupal Websites

    How to Audit Drupal Websites

    A website audit can be done in two ways. Bear in mind that these two ways are complementary to each other not…

    1 条评论
  • Created First Drupal 8 module

    Created First Drupal 8 module

    Name your module As with Drupal 7, the first job is to name the module. We need to create a machine name which will be…

社区洞察

其他会员也浏览了