pkram3r Posted March 22, 2021 Posted March 22, 2021 Hi team, I have a contact form in the footer of my website, so it appears on every page. Each home I am selling has its own page, and the footer appears on each page. When a user makes an enquiry I dont have an identifier to say what page the user was on when they submitted the form. The forms are coming through fine, but I'd love to have the URL it originated from. Any help would be awesome. Thanks. Beyondspace 1
Beyondspace Posted March 22, 2021 Posted March 22, 2021 1 hour ago, pkram3r said: Hi team, I have a contact form in the footer of my website, so it appears on every page. Each home I am selling has its own page, and the footer appears on each page. When a user makes an enquiry I dont have an identifier to say what page the user was on when they submitted the form. The forms are coming through fine, but I'd love to have the URL it originated from. Any help would be awesome. Thanks. You can add a hidden field on the form and use javascript to collect the page's path then assign to the hidden field value, when submit the url with come along BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox - PDF Lightbox popup - ...) </> 🗓️ Delivery Date Picker (Date picker form field) Gallery block 7.1 workaround </> No-code customisations for Squarespace
Beyondspace Posted March 22, 2021 Posted March 22, 2021 (edited) ⚠️ The script has been updated, kindly check the below reply for new Squarespace form blocks update on May 2023 ℹ️ 1. You assign the name of the hidden field and choose edit to get its generated name for the form, in this case it is 'footer-pagepath' -> 'SQF_FOOTER_PAGEPATH' (make sure it is unique name) 2. Add this snippet into settings->advanced->code injection->footer <script> document.addEventListener('DOMContentLoaded', function() { if (document.querySelector('[name="SQF_FOOTER_PAGEPATH"]')) { document.querySelector('[name="SQF_FOOTER_PAGEPATH"]').value = location.pathname; } }); </script> Edited June 14, 2023 by Beyondspace pkram3r, creedon and tuanphan 2 1 BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox - PDF Lightbox popup - ...) </> 🗓️ Delivery Date Picker (Date picker form field) Gallery block 7.1 workaround </> No-code customisations for Squarespace
pkram3r Posted March 22, 2021 Author Posted March 22, 2021 Thank you so much bangank36 that worked perfectly and exactly what I needed. I've sent you a DM Beyondspace 1
tuanphan Posted April 5, 2021 Posted April 5, 2021 @bangank36 Just want to say thank you. I helped a member with your code. Beyondspace 1 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!)
tuanphan Posted May 1, 2022 Posted May 1, 2022 On 4/5/2021 at 9:56 AM, tuanphan said: @bangank36 Just want to say thank you. I helped a member with your code. Thank you. Just used this for another friend site. One question, how can I get Product Name? @bangank36 Thank you again. 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!)
Hil Posted May 9, 2023 Posted May 9, 2023 Hi @bangank36 Newbie coder here. I've been using this since Sept 2021 and it's worked perfectly. But in the last week or so, I noticed it stopped providing the page path. Can you help me troubleshoot why that might be? Is anyone else having this problem? Thanks so much!! Beyondspace 1
Beyondspace Posted May 10, 2023 Posted May 10, 2023 8 hours ago, Hil said: Hi @bangank36 Newbie coder here. I've been using this since Sept 2021 and it's worked perfectly. But in the last week or so, I noticed it stopped providing the page path. Can you help me troubleshoot why that might be? Is anyone else having this problem? Thanks so much!! There are some breaking changes in Squarespace Form block that may prevent this from working, do you mind to share your current site URL to we can check it easier BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox - PDF Lightbox popup - ...) </> 🗓️ Delivery Date Picker (Date picker form field) Gallery block 7.1 workaround </> No-code customisations for Squarespace
Beyondspace Posted May 13, 2023 Posted May 13, 2023 Cross-post this comment while identifying work around for this BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox - PDF Lightbox popup - ...) </> 🗓️ Delivery Date Picker (Date picker form field) Gallery block 7.1 workaround </> No-code customisations for Squarespace
Beyondspace Posted June 14, 2023 Posted June 14, 2023 (edited) @Hil @pkram3r cc: @tuanphan in case you need to update your answer somewhere I updated the code for the latest update of Squarespace form blocks, kindly replace the current code on the footer injection. Please make sure the consistent of the hidden field name in the form block and in the custom code injection nit: you can change the field name if you want, just remember to update the variable <script> /* * @beyondspace: Append current page to sqs form submission * Squarespace Forum: 14-June-2023 */ window.addEventListener("load", (event) => { const hiddenFieldKey = 'SQF_PAGEPATH'; const formBlocks = document.querySelectorAll('.sqs-block-form'); formBlocks.forEach((block) => { const contextElement = block.querySelector("[id*=form-context-]"); const context = JSON.parse(contextElement.innerHTML); const hiddenField = context.formFields.filter((field) => { return field.key === hiddenFieldKey })[0]; if (hiddenField) { const hiddenFieldIndex = context.formFields.indexOf(hiddenField); const latestContext = JSON.parse(contextElement.innerHTML); latestContext.formFields[hiddenFieldIndex].value = location.pathname; contextElement.innerHTML = JSON.stringify(latestContext); Squarespace.initializeFormBlocks(Y, Y) } }) }); </script> nit: I updated the snippet a little bit to make it compatible with the IP hidden field here Edited June 14, 2023 by Beyondspace BeyondSpace - Squarespace Website Developer 🖼️ Lightbox Studio (Enable Pinch/Zoom on lightbox - PDF Lightbox popup - ...) </> 🗓️ Delivery Date Picker (Date picker form field) Gallery block 7.1 workaround </> No-code customisations for Squarespace
micaelRHT Posted July 8 Posted July 8 On 3/22/2021 at 2:10 AM, pkram3r said: Hi team, I have a contact form in the footer of my website, so it appears on every page. Each home I am selling has its own page, and the footer appears on each page. When a user makes an enquiry I dont have an identifier to say what page the user was on when they submitted the form. The forms are coming through fine, but I'd love to have the URL it originated from. Any help would be awesome. Thanks. Hi. I'm new here in the forum. How can I view or find the solution to your topic ? I have the same needs. Thank you
tuanphan Posted July 12 Posted July 12 On 7/8/2024 at 7:43 PM, micaelRHT said: Hi. I'm new here in the forum. How can I view or find the solution to your topic ? I have the same needs. Thank you Have you tried code in above comment? If it doesn't work, you can let me know, we can check easier 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!)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment