1

I'm using my own templates to modify forms, i.e. user registration form. In my custom template, I call drupal_render($form['field_email']); to get output for a text input used for taking user's Email.

However, this function returns so many outputs (including a Label which definitely I don't want, and a lot of divs) that break my design. What I require is a single <input name = "appropriate-name" /> but I'm getting:

<div class="field-type-email field-name-field-user-email field-widget-email-textfield form-wrapper" id="edit-field-user-email"><div id="field-user-email-add-more-wrapper"><div class="text-full-wrapper"><div class="form-item form-type-textfield form-item-field-user-email-und-0-email">
  <label for="edit-field-user-email-und-0-email">Email <span class="form-required" title="This field is required.">*</span></label>
 <input type="text" id="edit-field-user-email-und-0-email" name="field_user_email[und][0][email]" value="" size="60" maxlength="128" class="form-text required" />

A lot of HTML!

Is there a way to get minimum HTML required for a form input field to work properly?

Perhaps, I may end up with editing the #theme property for this field, to specify a custom theme function. But That's a lot of work to do, I think. Besides, I have many other fields for which I may need to write custom theme functions to get simple HTML for the input. Is there a quick way to get minimum HTML for a form field?

4

I can't advise that you remove the labels as your website will instantly become inaccessible and fall foul of disability discrimination guidelines.

That being said, you can override the output for all form elements by implementing an override of the theme_form_element function. The easiest thing to do would be to copy that function in its entirety into a function in your site's theme called MYTHEME_form_element(&$variables), and then step through the code trimming out the elements that you don't want to be output.

  • I already have labels hard-coded in the template file, So I don't need to worry about them right now. Is there a way to more precisely edit the theme_form_element function? Say, for user registration page only or for certain node type? Thanks for your answer. – Shafiul Mar 23 '12 at 11:26
0

You should take a look at semantic fields. Its lets you control the structure of HTML generated and helps you remove the clutter.

On the module page it says

The user can also choose to remove all (or some) markup for any field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.