Is it possible to gain full control in a Drupal form customization?
arnoldc - June 29, 2009 - 18:26
Hi guys,
Is it possible to get rid of the Drupal wrapper markups in a form? I have digged the internet just couldn't find the answer.
I know I can use hook_alter_form() to modify the $form array and I can use tpl to add necessary HTML markups around $form. But where should I go to control the form rendering to output the $form?
I need to control how Drupal renders an input element. For instance, if my $form has a a text field "mail", I just want to create the input tag without the Drupal wrapper [div class="form-item" id="edit-mail-wrapper"] tag.
It is currently done in Drupal_render() and my question is how am I suppose to override it. I must overlook something here..
Thanks in advance.

theme_form_element
You can override theme_form_element (http://api.drupal.org/api/function/theme_form_element/6) in your theme.
Oh thank you. I see all theme
Oh thank you. I see all theme functions can be override in my template.php. Now I see I have full control of every input element.
I can customize the form to match the design by getting rid of the [form-item] div. But I also took away the red border highlighted to the field in the event of an error. Wonder if where can I style it manually in this case?
By default, elements that do
By default, elements that do not validate, get the class "error" on the form element. Is that class still there, or did you cut that out when overriding the theme functions? You know, maybe this is not what you want to hear, but... If you first decide to override everything Drupal does for you and then say "hey, it doesn't work!", that makes it hard for me to help you.
Yes, I did see my text
Yes, I did see my text element gets the "error" class in case of validation failure.
Turned out I just needed to add the input.error on my stylesheet. Most themes use .form-item input.error to style form element error but this won't get pick up in my case since I get rid of the former tag.
Thanks again and mission accomplished.
You're welcome, glad you got
You're welcome, glad you got it working.