Altering Webform email %value before sending email I summon your wisdom on this day because I can't figure out how to alter submitted Webform values that are used in email templates.

Here's my situation:

I have a "contact us" form (set with Webform API) with first name, last name, email and message fields. Nothing spectacular. The submitted values are sent by email to the administrator.

In this webform setting > Email subject, I have this template:

[NAMEOFMYSITE | question from %value[first_name] %value[last_name]


Everything works fine. But my problem appears when the user forgets to put an uppercase in last name or first name value. It doesn't look professional in the email subject. And I want to force these two values with an uppercase as first letter to get something like:

NAMEOFMYSITE | question from John Doe


And never:

NAMEOFMYSITE | question from john doe


I tried to alter submitted values because I thought template's %value were based on it:

function pwe_webform_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  [...]
  $form['#submit'][] = 'contactus_webform_submit'; // callback function on submit
}

function contactus_webform_submit($form, &amp;$form_state) {
  $form_state['values']['submitted']['last_name'] = ucfirst($form_state['values']['submitted']['last_name']);
  $form_state['values']['submitted']['first_name'] = ucfirst($form_state['values']['submitted']['first_name']);
}


But even if I succeed to modify them, the %value in email doesn't change.

Of course, I dpm $form_state tree to see where the submitted values appear in it and where the template's %value could find its origin. It appears on several levels:


$form_state['input']['submitted']['last_name']
$form_state['values']['submitted'][2]
$form_state['values']['submitted_tree']['last_name']
$form_state['complete form']['submitted']['last_name']['#value']
$form_state['webform']['component_tree']['children'][2]['value'] (but always empty)


I altered every variable but the email value still the same. I'm about to ask myself if it is actually based on one of those variables... If not, on what is it based? And how can I alter it?

Please excuse the looooong post but I wanted it to be very clear. I hope you will help anyway :-(
In hook_form_alter, add a new submit function before the other submit handlers, like so:

pwe_webform_form_alter(&amp;$form, &amp;$form_state, $form_id) {
  switch($form_id) {
  case 'YOUR_WEBFORM':
       array_unshift($form['#submit'],'pwe_webform_form_submit');
       break;
  } 
}


And then write your submit handler, something like this:

function pwe_webform_form_submit($form, &amp;$form_state){
  $form_state['input']['submitted']['last_name'] = ucfirst($form_state['input']['submitted']['last_name']);
}


You can intercept the submit handler with dpm($form_state['values']) calls, to make sure you're using the right array keys, etc.