hook form_alter

rjerome - March 28, 2007 - 13:01

Hi all,

I'm the author of the biblio module (http://drupal.org/project/biblio), and recently I have been getting a lot of issue reports stemming from other modules use of the form_alter hook.

It seems that many other modules are using form_alter and setting the $form[#theme] to their own theme function and the obvious problem with this is that the original node form's theme function no longer gets called rendering my node form useless.

I think there should at a minimum be a note in the hooks documentation that if you want to use a custom theme function in hook_form_alter, you should NOT set it at the top level of the $form array, better yet would be to filter these theme settings out completely if form_alter attempts to set the top level form theme function.

Ron.

List the Traitors!!

coreb - March 28, 2007 - 15:10

Which modules are causing this? I'm asking this only so I can look at the modules that aren't "playing nicely" to see what specifically they are doing that isn't "nice".

RE: List the Traitors!!

rjerome - March 29, 2007 - 02:04

So far I've come across WebFM , Diff, and another called talk, but it doesn't really count since it's not officially released, one of my users downloaded it from the CVS sandbox.

In nodeprofile_privacy's

Coyote - October 3, 2007 - 23:34

In nodeprofile_privacy's hook_form_alter, there's a line...

$form['#theme']='nodeprofile_privacy_user_form';

... That prevents phptemplate_node_form from being called, so it's harder to theme the form. I just went in and commented out the line, and things were back to normal.

Could you give a code

ragaskar - July 20, 2007 - 20:33

Could you give a code example that shows the "right" way to re-theme an entire form using form_alter? I want to make sure my modules are as flexible as possible, but ATM I don't quite understand the 'best practice' you are suggesting -- are you saying that modules should attach a #theme to each form element rather than to the root of the form, or?

 
 

Drupal is a registered trademark of Dries Buytaert.