I've just started working with the AJAX module, and have noticed the following difference in control flow between the unaltered FormsAPI and how it behaves with the AJAX module enabled:

Unaltered FormsAPI:
1) call hook_form() to generate form
2) call hook_form_validate() to validate user input
(repeat step 2 until validation passes control to step 3) (note: step 1 not repeated)
3) Validation passed, call hook_form_submit() to process now validated user input

FormsAPI with AJAX module processing a AJAX enabled form:
1) call hook_form() to generate the form
2) call hook_form_validate() to validate user input, if validation does not pass, start over at step 1.
3) Validation passed, call hook_form_submit() to process now validated user input

The key difference being that with the AJAX module enabled, the form generation function gets called each time through a user-submit & validation versus the unaltered FormsAPI probably uses a cached version of the form when repeating a form to the user after a validation error.

My key interest in this difference is the question: should the hook_form() routine generating the form alter its behavior in any manner when detecting that it is being called 2nd or more times for the same information request from the user? If not, why the change in behavior? Why not just use the cached form the same as unaltered FormsAPI?

Comments

bsenftner’s picture

slight clarification: when hook_form() is called a 2nd time, I have user-edited values in the $form_state array passed to my hook_form() implementation - should I replace any of the original default form values with the user-edited form values?