6

I have an issue to show modal form on page load. This form will have 3 steps to submit. I've found CTools will suit the best. I'm newbie in drupal, that's why I've looked all tutorials ctools. Every example article tells how to show modal form by clicking on link. But I can't find any examples, how to load my modal form not clicking on link. I want to call it through AJAX after the page loads, but I don't know how.

Please, give me some advices.

5

This post I wrote a while back deals with CTools AJAX events at any time. It involves writing your own Javascript handler and executing it on page load.

    Drupal.CTools.AJAX.refreshElements = function() {
  var url = '/mymodule/ajax/refresh-elements';

  try {
    $.ajax({
      type: "POST",
      url: url,
      data: { 'js': 1, 'ctools_ajax': 1},
      global: true,
      success: Drupal.CTools.AJAX.respond,
      error: function(xhr) {
        Drupal.CTools.AJAX.handleErrors(xhr, url);
      },
      complete: function() {
      },
      dataType: 'json'
    });
  }
  catch (err) {
    alert('An error occurred while attempting to process ' + url);
    return false;
  }

  return false;
};
$(document).ready(Drupal.CTools.AJAX.refreshElements);

Set the URL to the callback URL of your module. The last line tells the ajax to happen on page load but this could be replaced to happen in response to the exact event you need it to.

  • 1
    The link to 'this post' is broken :(. – Peter Lozovitskiy Mar 28 '14 at 10:31
  • does it work for Drupal 7, I see it is for Drupal 6 – SsouLlesS Oct 10 '14 at 19:24
1

This article by zroger may be a little old about this exact subject, have you taken a look to it?

  • Please avoid link-only answers. – Mołot Mar 28 '14 at 10:32

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.