Jump to content

JQuery to auto populate form? Possible?

Go to solution Solved by paul2009,

Recommended Posts

I am working on a two-step form and want to send info from the initial form to the second for it to be more conversational.

The first form (ex. www.website.com/contact/) collects name, email, and why you're contacting us. (ex. select: hire us, job openings...etc.). Upon submitting, it validates the data and sends the user to the appropriate second form (ex. www.website.com/contact/jobs?fname=John&lname=Doe&email=john.doe@website.com). I have this working.

Next, I am using Jquery to grab the URL params and set the name and email fields so the user doesn't have to do this again. To do this, I am using something like this:

var firstName = urlParams.get('fname') );

$( 'input[name="fname"]' ).attr('value', firstName).val( firstName );

This works. However, when you click submit, the name and email fields are cleared and marked as an error.

Am I chasing something that is not possible due to form security?

Edited by Loophole
Link to comment
  • Solution
On 5/15/2023 at 5:07 PM, Loophole said:

I am using Jquery to grab the URL params and set the name and email fields so the user doesn't have to do this again.

As forms are now built using React, you cannot use this method. You'll need to use a React-friendly method. For more details, you may find the following helpful:

Simulating onChange events on React (post on Medium)

Did this help? Please give feedback by clicking an icon below  ⬇️

Edited by paul2009

About me: I'm Paul, a SQSP user for over 18 yrs and a Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL, providing high quality original extensions to supercharge your Squarespace website. 
Content: Views and opinions are my own. Links in my posts may refer to my own SF.DIGITAL products or may be affiliate links.
Forum advice is completely free. You can thank me by selecting a feedback emoji below. Buying a coffee is optional.

Book paid help with domains: Connect a GoDaddy domain. Connect a Squarespace Domain. Domain assistance

Link to comment
  • 3 weeks later...

I used HTML to pre-populate some data in a SS form, this was achieved using getelementID and setting the value of that text area/box. This code block still works BUT the second I click Submit, the data is deleted from the form.

What's changed and is there a workaround?

Link to comment
4 hours ago, howharvey said:

I used HTML to pre-populate some data in a SS form, this was achieved using getelementID and setting the value of that text area/box. This code block still works BUT the second I click Submit, the data is deleted from the form.

What's changed and is there a workaround?

Share website URL. I will check it out issue.

 

With over 450+ websites built, I create uniquely tailored Squarespace sites designed to meet your specific needs and preferences. Let's bring your vision to life!

💻 Check out My Fiverr Gig: Click Here

-------------------------------------------

Please like and upvote if my comments were helpful to you. Cheers!
Did I help? Buy me a coffee?

Link to comment
Quote

this issue only has existed since the rollout of the new "forms block". I can set values with JS within a form, but on submit those fields get cleared.

Hopefully this thread is more helpful. Please see the following.

 

Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects.

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.