1

I have a working module which opens a modal form with CTools. However, I must use the URL example.com/mymodule/page . There the module creates the link which opens the modal window with the form. How can I use the link in other pages? I have tried to just put the link and it does not work, it redirects to the page of the link (example.com/mymodule/nojs/) instead of opening the modal window.

  • The Anchror tag needs some special classes, and the modal JS needs to be added to the page first. Also, the page should return valid Ajax commands instead of raw HTML or render array. – AyeshK Nov 26 '14 at 16:27
  • I have added in template.tpl.php the following: ctools_include('modal');ctools_modal_add_js(); and the source code lists the same css and javascript. The ahref has the modal classes. But still it doesn't work. What makes me crazy is that it doesn't even open a popup. – Cesar Nov 26 '14 at 16:43
  • What do you mean ahref has modal classes? What classes exactly? I think it should be ctools-use-modal plus the modal theme name. Also, check the Drupal.ajax in Firebug DOM inspector. you should see the href value of the link there if Ajax is set correctly. – AyeshK Nov 26 '14 at 16:46
  • It is exactly that class ctools-use-modal. I thought I understood the process. I click on the link, as it is modal and has the class jQuery sees as modal, instead of redirecting, opens a new window in modal form, and when the URL is called, Drupal makes the Ajax call to retrieve the form. So I simply put the link in another page and it does not work, even it does not open in modal, which is the most absurd thing. – Cesar Nov 26 '14 at 16:56
  • This is unfortunately not the case. Modal JS scans the page (works as a JS behavior, so it's called on document ready event AND after an Ajax call) for the matching links and registers the Ajax object in Drupal.ajax. Adding or removing the class later in a particular anchor tag will not make a difference because Ajax functionality is already bound to it. Are you adding the class to anchor tags using JS? Can you see Drupal.ajax stuff? – AyeshK Nov 26 '14 at 17:00
0

I have finally solved the problem and now everything works: the modal window, the form and the submit, sending the email in final step. The problem was that the raw URL included the class ctools-use-modal-processed and apparently that simple css was making it not work. Now more or less understand the process, thank you for your help, it has been very valuable.

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.