Combining values from 2 fields and sending the result as hidden to next step
-
Hey there,
So what I’m trying to achieve is to take the values from 2 input fields which are numbers, add them and set the result of that sum to a hidden input field which I want to display on the next step. Through some googling I managed to write the following:
add_filter( 'wpcf7_posted_data', function ( $data ) { // ID of the form $form_id = 42; $form = wpcf7_get_current_contact_form(); if ( ! $form || $form_id != $form->id() ) { return $data; } $data['sum-total'] = $data['pup'] + $data['sch']; return $data; } );
The following input field is added to the form with the id 42.
<input type="hidden" name="sum-total" />
And this is inserted on the next page which should display the content of the field ‘sum-total’.
[multiform "sum-total"]
Sadly no matter what I do ‘[multiform “sum-total”]’ returns an empty value, unless a default one is set on the previous step like so ‘<input type=”hidden” name=”sum-total” value=”Some value” />’.
Any ideas why is the above code not working? Any help would be greately appreciated.
- The topic ‘Combining values from 2 fields and sending the result as hidden to next step’ is closed to new replies.