New Podcast

Posted Tuesday, January 31 at 3:28 pm
  Thomas Turnbull (tom_o_t on drupal.org) and Alan Palazzolo (zzolo on drupal.org) join Mike Anello to talk about their new book from O’Reilly Media, Mapping with Drupal. Mike’s usual co-hosts, Andrew and Ryan, were both unable to participate in the podcast, leaving Thomas and Alan subject to Mike’s long-winded (but extremely interesting by some accounts) questions.
Download Podcast 73
DrupalEasy_ep73_20120131.mp3
Syndicate content

NEWSLETTER

Stay informed on our latest news!

Syndicate content

Testimonial

DrupalEasy is by far on of the best ways to learn Drupal; Mike & Ryan completely immerse you into the complex world that is Drupal. Their easy to understand teaching technique and approach to explaining site administration, in a way any newbie or long time Drupaler can understand, makes the DrupalEasy workshops an important and invaluable experience for anyone who wants to become a Drupalista.

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