I have a webform (version 4.11 on Drupal 7) that is failing QA test because the javascript validation is not correctly attaching to an empty required form element-- the 'Please fill out this value' tag is going to the top of the screen instead of near the element that failed validation.

So as a work-around, I decided to add a hook_form_alter and a new validation callback, to manually perform the validation. I am setting the error messages with drupal_set_message.

It turns out that the $form and $form_state arrays for webforms are apparently different from the typical form. Instead of $form_state['values']['field_key'], I found them here: $form_state['input']['submitted']['field_key'].

However, I can not figure out where each field's #default_value key resides in the $form array. I would expect it to be $form['field_key'], but it's not there.

How can I pre-populate the default value of form elements in a webform with hook_form_alter?

2 Answers 2


I found the values here


So for the first component, I would change the value like so

$form['#node']->webform['components'][1]['value'] = 'test';

You can use the following:

$form['submitted']['component_name']['#value'] = 'test';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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