Sometimes when using the Drupal Webform module, you may want to do some calculations and then fill in a hidden field after the form has been submitted. For example, if we needed to calculate a total amount from the values of a few numerical fields, it might look something like this.


$total_amount = $form_values['submitted_tree']['pizza_price'] + $form_values['submitted_tree']['donut_price'];
//Then we have a hidden field with a component ID of 8 and we set it's value like this
$form_values['submitted'][8] = $total_amount;
$form_values['submitted_tree'][8] = $total_amount;

To get the component id, hover over “Edit” next to the component in your list on the webform and the id will be in the url after “components/.”