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
Link to comment
  • 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

About: SQSP User for 17 yrs. Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF Digital, building Squarespace Extensions to supercharge your commerce website. 
Content: Links in my posts may refer to SF Digital products or may be affiliate links.
If my advice helped, you can thank me by clicking one of the feedback emojis below. I love coffee too.

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.

Please feel free to message if you need any assistance. I'll reply within 24 hours. You can also send a forum message.
If you appreciate my assistance and would like to make a donation, please click here. Your support is greatly appreciated!

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.