Append data from webflow form to URL

Hi,

I am trying to find a solution on how to pass form data into a redirect URL by using the webflow form.

To make it simple, my form only consists of an email field and I want the email address of the user to be appended onto the redirect URL. E.g.:

  1. user goes to example.webflow.com
  2. user enters example@test.com in a webflow form and hits submit
  3. user gets redirected to Native Advertising & Redirect | Redirect.com

Is it possible to do it with the webflow form or does one have to use custom code? If custom code is to be used, what would it look like and can one style it?

I’ve been reading plenty of forum threads about the topic and the guides but have not been able to figure out how to do it.

Cheers,
Philip

Something like this perhaps?

Demo: Pass form field to redirect URL

Share link: Webflow - Sandbox

<script>
Webflow.push(function() {
  $('form').submit(function() {
    setTimeout(function() {
      location.href = 'https://samliew.com/webflow-expert?email=' + $('#email').val();
    }, 100);
  });
});
</script>

It gets redirected to another form and the target page auto-fills the email.

Another Demo: Form 1

6 Likes

@samliew

How would you next attach this email to an email form on the next page?

Hello @DomenVi, have you solve your issue ? I’m interested by the answer… :slight_smile:

Hi @samliew

Thank you for your answer to this question, it is very helpful!

Question though, if I am looking to append more than one field to the end of my URL what changes would I make to the custom code? For example sake, say I wanted to append email, name, and phone number to the end of the URL below.

‘Top Webflow Expert Web Developer’ + $(‘#email’).val();

Thanks in advance!

Paul

@samliew I’m guessing its hopefully as easy as adding the other input ID’s to the end of the URL string?

Thanks again!

1 Like

you’ll need to include the field names as well.

'https://example.com/?email=' + $('#email').val() + '&phone=' + $('#phone').val()

Thanks so much for the help @samliew

Hi @samliew,

how can I create this with two forms linking to different pages from the same page?

am I right in thinking something like the below?

Thanks!

I would seriously not reccomend doing this since it may violate GDPR terms and you might get into serious trouble.

If you have users in the EU and happen to use any third party script that analyses URLs (like google analytics of facebook pixel, just to name very commonly used examples) you are serving pii (personal identifiable information) to that service, which is a very serious violation of GODR terms.

I don’t know what you want this for, but just thought I’d mention it for you to keep it in mind.

Fines for violating GDPR terms go up to 20 million euros.

@samliew How to make it open in new tab?

Thanks!

Thank you! This was very helpful!

Hi Samliew. How would you do this with two forms on the same page? The script works for the first form, but not the second (lower) one. Thanks :slight_smile:

I wound up using sessionStorage to achieve the outcome I was looking for.

It’s not best practice to store sensitive information in the browser like this and probably violates GDPR unless you disclose what you’re doing with the information. But I’m not passing along anything egregious in my case and at least storing it in the session clears it eventually (as opposed to localStorage). I also clear it after the form submission.

I preferred to use this on .submit() and use webflow’s default form behavior for redirects and response messages.

Here are decent docs on sessionStorage.

1 Like

This code works for me on web, but not mobile. Has anyone experienced this?

If i do this there is no form submission on the 1st page.

How do i get that?

Thanks for the script, it’s perfectly working on Chrome, but the form is not submitted on Safari and Firefox (with message error, but the new link is well oppened). You can check on your demo.
Do you know how I can fix this issue ?
Thanks for your help.

Hy @samliew! This topic is pretty old but I’m trying to implement URL changing after the Contact Form is submitted and need some help. Your script works fine but after I implemented it my form stopped sending notifications about new submissions and they’re not showing in a form submissions at all. Could you please help me with this?

Contact support. I can’t help with hosting issues.

@Philip_Kornmann This looks like what you need…

If you need an explanation on what’s going on, just chuck the code into ChatGPT and it will explain…

The short of it is…

  1. Copy this code & place it in the before /body area
  2. Replace the ID’s of your submit button & webflow form
  3. Replace the redirect URL & any parameters you want to be tacked on
  4. Put your Webhook URL in the “action” for the form
  5. Make sure the form is using the POST method

The email validation is not necessary, but I put it in there so you can block common bot email addresses or misspellings of common email domains. That part disables the submit button until they correct their email address.

Hope this helps someone who needs it!

<script>
  $(document).ready(function() {
    var blockedDomains = ['tempormail.com', 'temporary-mail.net', 'temporary-mail.com', 'tempomail.com', 'tes.com', 'test.com', 'favilu.com', 'soremap.com', 'tempo-mail.com', 'tempo-mail.net', 'tempormail.net', 'ratedane.com', 'larland.com', 'ozatvn.com', 'valanides.com', 'peogi.com','farebus.com', 'gmail.co', 'gnail.com', 'ysahoo.com', 'peogi.com', 'pyadu.com'];  // Add blocked domains here

    function validateEmail(email) {
      var domain = email.split('@')[1];
      return !blockedDomains.includes(domain);
    }

    $('input[name="email"]').on('blur', function() {
        var email = $(this).val();
        if (!validateEmail(email)) {
          alert('Invalid email address.');  // Show an alert or customize as needed
          $('#YOUR-SUBMIT-BUTTON-ID').attr('disabled', 'disabled');  // Disable submit button
        } else {
          $('#YOUR-SUBMIT-BUTTON-ID').removeAttr('disabled');  // Enable submit button if email is valid
        }
    });

    $('#YOUR-FORM-ID').on('submit', function (ev) {
        ev.preventDefault();
        
        // original form action url
        var actionUrl = $(this).attr('action');
        console.log(actionUrl);
        
        // get for data
        var formData = $(this).serialize();
        console.log(formData);
        
        var form = $(this);
        
        $.ajax({
        		type: 'POST',
            url: actionUrl,
            data: formData,
            success: function (data) {
                var fname = form.find('input[name="firstName"]').val();
                var email = form.find('input[name="email"]').val();
                var phone = form.find('input[name="phone"]').val();
                window.location.href = "https://yourdomainname.com?firstName="+encodeURIComponent(fname)+"&email="+encodeURIComponent(email)+"&phone="+encodeURIComponent(phone);
            },
            error: function (data) {
            		console.log('Error:', data);
      			}
    		});
    });
  });
</script>```