Although IMHO Drupal's spin on AJAX is still fairly horrible compared with the amazing Partial Page Rendering/Update technology of JavaServer Faces (JSF) and 3rd party JSF toolkits like Primefaces, the Drupal7 Forms API makes it easier than previously to handle AJAX updates. From Form API Changes for Drupal 7, Part 2: AJAX/AHAH Changes:
One of the many pleasant improvements to the Drupal Form API is that AJAX Forms are now really easy. Really easy. We used to call them AHAH forms, and the concept was the same, but they were so complicated that few people attempted them. In D7 we even changed the name to distance ourselves from "AHAH" :-)
Well, no, just a lot easier in Drupal7 than it was in Drupal6. As a huge fan of (and very experienced with) JavaServer Faces (JSF2), I think it's fair to say that JSF2 users have enjoyed using elegant, sophisticated, powerful AJAX for many years as easily as spreading warm butter on toast. As usual, certain "I live in a tiny Drupal fishbowl and have just discovered programming and made a web site and am so excited" Drupal Religion fanatics are easily impressed, because they have clearly not seen and experienced other Information Technologies (IT). I have experienced both; I know how the Drupal7 AJAX facilities work, and JavaServer Faces (JSF2) wins hands down, no question, no argument.
Dr Darren, Webel IT Australia
But back to Drupal (this is a Drupal7 site after all). From Ajax Forms in Drupal 7:
'Ajax-enabled forms in Drupal 7 offer dynamic form behavior with no page reloads and are easy to create and manipulate. They are a simple extension of the Drupal Form API.
What is dynamic behavior? Traditional web behavior has the user fill in a form, click a button, and the entire page is rebuilt and sent back to the browser. Ajax-enabled forms update or replace part of the page or part of the form without doing a full page reload - only the part that needs to be changed is changed. It's more responsive to the user and typically faster than the traditional page reload approach.'
It is worth noting that:
Core Drupalers tend to use the word 'Ajax' rather than the almost-acronym 'AJAX'.
In Drupal 6 to carry data back to your form builder you set the storage key of $form_state in your submit handler. In Drupal 7, upon return to your builder after submission, you carry data over by keeping the Form API from pulling the form array out of cache*. You do so by setting $form_state['rebuild'] to TRUE in your validate or submit handlers
© Copyright 2001 - 2016 Webel IT Australia (ABN: 67 677 268 579). All rights reserved (except as specified below).
PHP code examples from Webel IT Australia on this site are distributed under the GNU General Public License.
Excludes text and code snippets from Drupal.org quoted for educational purposes.
Drupal’s online documentation is © 2000-2014 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0.
PHP code from Drupal.org is distributed under the GNU General Public License.
Drupal® is a registered trademark of Dries Buytaert.
Text quoted from Wikipedia for educational purposes is made available under the Creative Commons Attribution-ShareAlike License.
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.
Site developed by Webel IT Australia.