Skip to Content

Drupal Form submission

I've made some significant, but truly hard-won progress. Getting things done the Drupal way is really really hard when you don't know how. So, here's what I've learned.

Form Submission Woes Solved

My son Peter built me a very simple module that puts node-specific student notes into a side panel. He basically copied some stuff from the FAQ-Ask add-question block. The problem is, when you click the 'Save' button, the whole page reloads. Took me weeks to figure out the best way to overcome this.

My first clue was AJAX. AJAX stands for something like Asynchronous javascript and xml, which is less than enlightening, but I figured out that one of the things it is commonly used for is updated pieces of an html page without reloading the whole page. Sounded perfect, so I Googled it up.

The AJAX Module

Right away I found a module that seemed to do the trick. I installed and enabled the AJAX module, copy/pasted 3 or 4 lines of code from the documentation into my son's module, and bingo! I thought my problem was solved. Not so.

Unfortunately, the Ajax module started throwing errors at me, and also tended to make admin interfaces less user-friendly. Lots of forms started submitting via Ajax, and this was not always a good thing. I hacked the module a bit to disable it on Admin pages, but in the end it was back to square one.

The AHAH ah ha

I googled around a bunch more, and was doing some general research into jquery in drupal, and finally stumbled across AHAH, which is sort of like Ajax without the javascript or xml. Although I am a heavy user of xml, AHAH was sufficient for my immediate needs, and the documentation for implementing AHAH with Drupal forms is ridiculously better than anything I was able to dig up on AJAX. As a fabulous side-benefit, I learned vital things about Drupal's menu system, which, as it turns out, does much more than provide links. Some menu items serve as a secret access port to php functions. Brilliant!

For my next trick, I'm going to attempt to combine the Student Notes module with an enhanced version of my e_page module. I'm thinking of the following new features:

  • A lab notes option in the side panel. This might just be a back door to submitting a WebForm. This solution has the advantage that the interface for creating appropriate fields already exists, but the downside that WebForm fields are not exposed by views.
  • A jquery version of my existing xml-driven glossary.
  • An AHAH enabled form that could silently capture data from my existing side-panel self-test.
  • An AHAH enabled form that can pass information from any Flash content to a db table. Actually, this part is built, I so far it only captures a single score. I'm thinking of expanding it to capture more data.