Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

Auto-populate the Country field in the Contact Form


MelenMan

Question

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 post
  • Answers 6
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

Popular Posts

I, too, am looking to resolve this. Once I figure it out, I will update you.

6 answers to this question

Recommended Posts

  • 0
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.

Link to post
  • 0

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 post
  • 0

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 by Inscape
Link to post
  • 0

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 by OliverOrtega
Link to post
  • 0

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 by kirkroberts
Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...