[development] drupal_rebuild_form on node preview

Dave Cohen drupal at dave-cohen.com
Mon Jul 14 23:48:42 UTC 2008


I'm running into a problem having to do with drupal_rebuild_form.  I hope 
someone can explain to me what is going on.

The symptom, briefly is this:  I have a custom form element, with its own 
#process function.  The function relies on $element['#post'] to do some of 
its magic.  In Drupal 5, it works fine.  However in Drupal 6, when my form 
element is in a node form and I hit Preview, things break.  On Preview, my 
process function is called normally, then my process function is called with 
#post unset (as if the submit button had not been pressed).  And the form 
rendered to the screen is a result of this second invocation.

So in trying to debug this I learned about drupal_rebuild_form.  I've read the 
comments, but its still unclear why this function exists.  Its also unclear 
why its being invoked on node preview.  Is it because node module is setting 
$form_state['rebuild']?

Most important, can anyone suggest a workaround?  Do I have to implement a 
process function that can somehow detect whether its been called before?  Do 
I have to keep my own copy of #post around?  Is FAPI really supposed to 
process my element twice?

Thanks for any help,  -Dave


More information about the development mailing list