Accessing form answer values in form confirmation dialog
Hi everyone,
I’m trying to display a value in my form confirmation dialog based on the answers submitted in the form. To be clear, I’m not trying to display the values themselves, so the dynamic insertion doesn’t help.
I cannot so far find a way to access the form values in javascript to use them. Any help would be appreciated!
Thanks 🙂
Page 1 / 1
For a little more info, I just don’t know what to look for…
I’m assuming they’re around somewhere since the dynamic insertion can find them.
So far, the workaround I’ve figured out is to load another URL in a lightbox instead of the form confirmation dialog, passing the values in parameters there and then parsing the URL to display what I want in the page. But it would be a lot cleaner if I could stick to the confirmation dialog vs creating a separate page in unbounce.
@GregorySR Let me take a shot at how I will do this.
I will add a hidden field to the form and call it anything that you want to display on your form confirmation dialog (lets say x)
Then before form submit, I’ll calculate the value of x (based on user responses) and pass that into with the form submission data as a value of this hidden field.
In the form confirmation dialog, we can then use dynamic text to display it 😉
I did a 1 field form. The values in the headline of form confirmation box will change depending on what you choose.
Of course… There could be other ways of doing it too!
Thanks @Malik! That’s a clever solution, hadn’t thought of trying to calculate the results first and passing them through.
So I’m guessing you’d detect the “onClick” for the submit button and then field.value = result?
However, I’m still having trouble accessing the selected values. I did find an example script for a dropdown, but in my case I have a couple of radio buttons and a text field and cannot figure out how to get the selection / value.
I am a huge fan of unbounce hooks to manipulate form submissions. Posted the link below.
Here is the script I am using on the sample page
<script>
window.ub.hooks.beforeFormSubmit.push(function(args) {
var pet = args.formElement.querySelector('select#favorite_pet'); // replace with your form ID
var person = args.formElement.querySelector('input#person_type'); //replace with your hidden field
pet.value = pet.value.trim();
// Do the calculations