Jump to content

Autofill Custom Form Subject Field with Product Title?

Recommended Posts

  • Replies 4
  • Views 1k
  • Created
  • Last Reply

Top Posters In This Topic

Posted

I don't know this, but if you want to get Product URL, you can follow these.

You can add a Form Block with Hidden Field

Label: Page URL

autofill-page-url-form-block1-min.png

then use this code to Pages > Website Tools > Code Injection > Footer

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (document.querySelector('[name="SQF_PAGE_URL"]')) {
    document.querySelector('[name="SQF_PAGE_URL"]').value = location.pathname;
  }
});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted
On 6/5/2024 at 3:41 AM, tuanphan said:

I don't know this, but if you want to get Product URL, you can follow these.

You can add a Form Block with Hidden Field

Label: Page URL

autofill-page-url-form-block1-min.png

then use this code to Pages > Website Tools > Code Injection > Footer

<script>
document.addEventListener('DOMContentLoaded', function() {
    if (document.querySelector('[name="SQF_PAGE_URL"]')) {
    document.querySelector('[name="SQF_PAGE_URL"]').value = location.pathname;
  }
});
</script>

 

Hey!
Sorry, I've been traveling.
I'll give this a try in the next day or so.

Thank you!
PLT

Posted
On 6/5/2024 at 3:41 AM, tuanphan said:
<script>
document.addEventListener('DOMContentLoaded', function() {
    if (document.querySelector('[name="SQF_PAGE_URL"]')) {
    document.querySelector('[name="SQF_PAGE_URL"]').value = location.pathname;
  }
});
</script>

Hello.
I tried this a few times, returned no value.

Thoughts?
Thanx.

Posted

Ah, I forgot, I just test a new code, you can see this demo

https://herring-duck-dk5w.squarespace.com/shop/product-01

pass: abc

image.thumb.png.0c3f63e3e4db693782e31ae8f4224429.png

The form will be like this. Here I used Text Field for Page URL.

(Edit Mode)

image.thumb.png.76cd17bdfa422953042fd1660deb2389.png

(Outside)

image.thumb.png.9d4ea204cd32081bfc0ae51d68b85915.png

If you agree this, I will send new code. 

With this, if you have 10 products, you will need to add Form to 10 Products, or you can add Form to Footer, then we will use code to move it to 10 products

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

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.