Jump to content

Pass entered email value from form to a thank you page URL parameter

Recommended Posts

Hi!

I'm trying to build the following scenario using Cover Page:

1. User enters an email on a page with a sign-up form.
2. Once submitted, the user is redirected to a /thank-you page, and the entered email address is set as a URL parameter: /thank-you?email=<user_email>.
3. We then use that parameter on the /thank-you page.

While I've managed to make this work using a regular page and form, the scenario doesn't work with Cover Pages. I tried to add the following code to the POST-SUBMIT HTML form option and the Advanced page option. But it doesn't work (no errors, so I think it might be ignored).

Can anyone advise if there is a solution, please?



###
<script>
document.addEventListener('DOMContentLoaded', function() {
  var form = document.querySelector('form[data-form-id="123456"]'); 
  
  if (form) {
    form.addEventListener('submit', function(event) {
      event.preventDefault(); // Prevent default form submission
      
      var email = form.querySelector('input[type=email]').value; // Get the value of the email field
      var redirectURL = '/thank-you?email=' + encodeURIComponent(email); // Construct the redirect URL with email as a parameter
      
      YUI().use('node', 'squarespace-form-submit', function(Y) {
        (new Y.Squarespace.FormSubmit(form)).submit({
          formId: '123456',
          collectionId: '',
          objectName: '',
          redirectUrl: redirectURL 
        });
      });
    });
  }
});
</script>
###

Link to comment
  • Replies 1
  • Views 1.4k
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

If your code worked on another page and on this not it might be because the Post Submit HTML only supports HTML lately.

Check: 

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.