Sending email to hidden field using webform after calling hook_form_alter? Drupal 7.14, Webform 7.x-3.17 : I built a webform that has a hidden field "lt_email", and I'm assigning a session value to it using hook_form_alter -

function wbl_form_webform_client_form_1_alter(&amp;$form, &amp;$form_state) {
   $form['submitted']['lt_email']['#default_value'] = $_SESSION['Some']['Email'];
}


When I var_dump or dpm the ($form) I see the session value for lt_email, but after I hit submit on the webform, the value goes away, it doesn't get assigned.

Since %session[id] didn't handle multi-dimensional session arrays, I used the hook_form_alter workaround. I was under impression hook_form_alter would grab the session value, assign it to hidden field, and once submitted, the hidden field would retain the value, which I then use as the email component for the webform that gets triggered automatically. THe hidden field is blank upon submit.

I'm logged in as root, and all the other fields retain value upon submit (ie, name, address).
The problem is probably caused by the hidden field having the #value property set which overrides #default_value (even if the former is NULL or a empty string).

To get the desired result you have 2 options:

1) Override #value instead of adding a #default_value:

$form['submitted']['lt_email']['#value'] = $_SESSION['Some']['Email'];


2) Unset #value then add #default_value:

unset($form['submitted']['lt_email']['#value']);
$form['submitted']['lt_email']['#default_value'] = $_SESSION['Some']['Email'];


If you are wondering which option is the right one for you then #default_value means that Drupal will accept client-side changes to the field value (via javascript for example). If you don't need/want that possibility then #value should be used (Drupal will ignore any client-side changes in that case). It's mentioned in the documentation as well.