MelenMan Posted April 13, 2020 Share Posted April 13, 2020 I built a small landscaping site. All my business is in the US and I would like to either remove the Country field from the contact form or auto-populate it to fill with USA. Is there some custom code for doing this. I am very comfortable with adding custom code to a Squarespace site. Link to comment
SummitSnow Posted May 4, 2020 Share Posted May 4, 2020 On 4/13/2020 at 11:14 AM, MelenMan said: I built a small landscaping site. All my business is in the US and I would like to either remove the Country field from the contact form or auto-populate it to fill with USA. Is there some custom code for doing this. I am very comfortable with adding custom code to a Squarespace site. I, too, am looking to resolve this. Once I figure it out, I will update you. MelenMan 1 Link to comment
andreashirey1914 Posted May 18, 2020 Share Posted May 18, 2020 After digging through this for a few hours, I found the following code works great to remove the Country field: Squarespace 7.0 - regular form block .form-block .country { display: none; } Squarespace 7.1 - form opening in lightbox mode .lightbox-content .field.country { display: none; Link to comment
Inscape Posted June 22, 2020 Share Posted June 22, 2020 (edited) In addition to @andreashirey1914's snippets above, this works for a form in lightbox mode in 7.0: .field.country {display: none;} Just make sure you don't have the Address set as a required field, or they won't be able to submit the form since there's no way for them to fill out the Country field. Edited June 22, 2020 by Inscape Link to comment
OliverOrtega Posted July 24, 2020 Share Posted July 24, 2020 (edited) I tried this and even if it is not required, the form is still asking for a Country. If you remove the code and your user/buyer enters only Address, City, Zip, even if not required, IT WILL still ask for a Country. I'm beginning to realise now that Squarespace is just so dumb. Edited July 24, 2020 by OliverOrtega Link to comment
kirkroberts Posted October 1, 2020 Share Posted October 1, 2020 (edited) This isn't the world's best coding, but it works on a 7.0 site (might work on 7.1, haven't tested it). Add this to the page's header injection, or to the site-wide injection (for all pages). It should auto-populate the country field. Note: it will only find the first instance of a country field, not multiple forms per page if it doesn't find a country field it will continuously run in the background... in most cases that is not a big deal, but it isn't good form. So probably best to only add this code to pages that have an Address field on them. Hope that helps someone. <script> function fillCountryField() { var field = document.querySelector('.field.country .field-element'); if (field) { field.value = 'United States'; } else { setTimeout(fillCountryField, 500); } } fillCountryField(); </script> Edited October 1, 2020 by kirkroberts Link to comment
TimWilson Posted April 26, 2021 Share Posted April 26, 2021 I'm trying to figure out how to do something similar. I have a simple form on a 7.1 site and I'd like to auto-populate a coupon code into the "Offer Code" field of the form based on data gleaned from the URL. (Nothing about the codes are secret in any way. This is just a convenience thing.) I'm able to get the coupon code from the URL (e.g., site.com/form-page?code=12345) into my variable via javascript, but it seems like I'm having trouble selecting the input field and pasting the value of that variable. Here's a snippet of the relevant form HTML: <div id="64ba7865-b8b9-4e6d-8a30-cb7b00c984d3" class="form-item field text required"> <label class="title" for="64ba7865-b8b9-4e6d-8a30-cb7b00c984d3-field"> Offer Code <span class="required" aria-hidden="true">*</span> </label> <input class="field-element text" type="text" id="64ba7865-b8b9-4e6d-8a30-cb7b00c984d3-field" placeholder="ALG-" aria-required="true"> </div> Any suggestions? I've tried using querySelector on the input id as well as the class. (It's the first instance of an input with that class, so it should be relatively straightforward.) Link to comment
creedon Posted April 26, 2021 Share Posted April 26, 2021 @TimWilson Please post the URL for the page your site with the form. If your site is not public please set up a site-wide password, if you've not already done so. Post the password here. Adding a site-wide password is not a security breach. Please read the documentation at the link provided to understand how it works. We can then take a look at your issue. Find my contributions useful? Please like, upvote, mark my answer as best , and see my profile. Thanks for your support! Link to comment
TimWilson Posted April 30, 2021 Share Posted April 30, 2021 (edited) @creedon, here's the link: https://www.acuityleadershipgroup.com/test-drive You can test passing the code by adding a "c" variable to the URL like this: https://www.acuityleadershipgroup.com/test-drive?c=12345 Edited April 30, 2021 by TimWilson Link to comment
Firstep Posted March 3, 2022 Share Posted March 3, 2022 How did this go @TimWilson ? I'm trying to do something almost identical. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment