my blog_Drupal 6 Popup Forms

18.04.2011

I did a lot of searching for a nice solution to make simple "confirm this action" type forms in Drupal 6 work as popups rather than directing the user to a new page.

At first the solution seemed to be the Popups module (http://drupal.org/project/popups). However on installing this and testing it on a development site I found it didn't work "out of the box". The reason turned out to be a conflict with Typekit. I disabled the Typekit module and it worked fine. However, this made me suspicious (and besides I wanted to use Typekit) so I did some research and found out that there is also an unresolved conflict between the Popups module and standard javascript optimization in Drupal. That ruled it out as far as I was concerned.

A better solution seemed to be the Modal Frame API, which I hear has been brought into core for Drupal 7. However this looked like quite a lot of work for me in creating my own custom module or implementation of the API. Possibly I would have done it eventually, but I did some more searching and found...Automodal! This module does exactly what I wanted. It implements the Modal Frame API and gives you a selector in your Automodal settings page. Add this selector to the link that you want to appear in a Modal Frame and it just works!

My real-world implementation of this was for node subscriptions. I wanted users to be able to click "Subscribe" on nodes or node teasers, and not to have to go to a pointless interim page just to click a "subscribe" button. So by enabling Modal Frame API and Automodal, and adding the "automodal" class to my link, I was able to make the subscribe form pop up. Joy! The only problem was that once they submitted the form, the parent page didn't refresh. A quick bit of Googling later and I discovered the useful hint to append "?automodalReload=true" to the end of my link. Double joy!

The only disadvantage is that it's not as fast as a true Ajax-only solution; the Modal Frame loads a full Drupal node, then reloads the parent page when it's finished - so my popup solution feels a little slower than it should be. However it does the job, and I'm happy.

www.flickr.com/photos/alanpeart