Jump to content

JQuery to auto populate form? Possible?

Go to solution Solved by paul2009,

Recommended Posts

Posted (edited)

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
  • Solution
Posted (edited)
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

Me: I'm Paul, a SQSP user for >18 yrs & Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF.DIGITAL. We provide 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. Buying a coffee is generous but optional.

  • 3 weeks later...
Posted

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?

Posted
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?

Posted

Sorry, should have explained better... 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.

Posted
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.

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.