Training

Our next U.S. stop:

Mike Anello and Andrew Riley from Mediacurrent are teaming up to offer the first Blue Collar Git workshop on Friday, June 8 as part of DrupalCamp Charlotte (also part of the Southeast LinuxFest). The cost is only $149 for the full day if you register during the month of May ($199 otherwise). 

New Podcast

Posted Wednesday, May 9 at 7:50 am
Brandon Morrison (Brandonian on drupal.org) joins Andrew Riley and Mike Anello on the first post-DrupalCon Denver edition of the podcast to talk about all things Geo in Drupal 7. Brandon is one of the maintainers of the GeoField module and is an active member of the Drupal Geo community.
Download Podcast 82
DrupalEasy_ep82_20120509.mp3
Syndicate content

Newsletter

Stay up-to-date on DrupalEasy workshops and other events. On average, we send about one newsletter per month.

Testimonial

Mike is a great teacher!

Who are we?

DrupalEasy is the collective expertise of Ryan Price and Michael Anello, who joined forces to provide training and consulting services worldwide. Read all about them and what they can do.

What is Drupal?

Drupal is a free, super-powerful content management system for sites that require information posting and collection, including blogs, forums, videos, photos, and databases of information. We think it is the best platform available. Here's why...

Why Drupal?

More and more savvy organizations are going with Drupal for content management, and its no mystery why. It’s free, flexible, and easy to maintain for small or large volume sites. Learn more...

Module Development: Adding Form Fields via AJAX/AHAH

Adding form fields to a Drupal form dynamically is not the most straight-forward task. You'll see this occasionally on a Drupal form (poll module jumps to mind) when there is an "add another" button that (seemingly) simply adds another set of input elements to the form. The big sticking point in setting this functionality up is doing it in a way that keeps FormAPI's security intact. Fortunately, there's some tips to get you mentally started.

I say "mentally" because the process doesn't really involve adding form fields - it is actually an exercise in manipulating FormAPI's $form_state array. You see, the $form_state variable is the key to keeping the security system happy. If the $form_state variable doesn't agree with the form that is submitted, bad things happen. Once you accept this, then the process makes a whole lot more sense.

Basically, what happens when the user clicks the "add another" button is the $form_state variable is modified with the new form fields. FormAPI then uses this updated $form_state to re-generate the form and send back the updated portion via AHAH.

There's an invaluable page at Drupal.org with all the details. In addition, I've found the source code of the Quicktips module a great source of reference as well.

Trackback URL for this post:

http://drupaleasy.com/trackback/125
No votes yet

More Quicktips


Syndicate content