views:

662

answers:

3

Another question about Drupal webforms -- The form itself is built in by /includes/form.inc's

function theme_form_element($element, $value)

and adds a <label> element to the $output. I want to remove that label only for one webform, so I have to override the function. How can I override it for only one webform, while leaving it the same in all others? E.g.

if ($block == 'contact'):
  // only output <input> form element stored in $value
  function mytheme_html_form_element($element, $value) {
    $t = get_t();
    $output .= " $value\n";
    return $output;
  }
endif;

Is this possible, and what goes in the if condition?

+4  A: 

If you're just looking to remove the label, you can also use hook_form_alter(), and check that $form_id is equal to the webform in question. The id will be of the form: webform_client_form_N where N is the node ID of the webform.

Once you're operating on the proper form, you can unset the label using, for example, code like this:

 unset($form['submitted']['first_name']['#title']);

Which would unset the label for a field called first_name.

jhedstrom
A: 

I wouldn't unset form element titles. You could get unexpected results when your form gets rendered by the theme engine.

You can do it several ways:

Theme each element or the whole form with with '#theme' => 'my_callback'.

You can also create your own form element using hook_elements that uses a corresponding theme hook.

See:

http://api.drupal.org/api/drupal/developer--topics--forms_api_reference.html

http://api.drupal.org/api/function/hook_elements/6

Rimian
A: 

i did have to do a hook_form_alter, but the label itself was in the ['submitted'] element. here is the code

  if($form_id == 'webform_client_form_18') {
    $form['submitted']['#children'] = '
    <input
     type="text" 
     maxlength="128"
     name="submitted[email]"
     id="edit-submitted-email"
     value="' . $form['submitted']['email']['#default_value']. '"
     class="form-text required"
    />
  ';
  }

in a different form, removing the #title worked (+1 for you!), but this was a different case.

davidosomething