Contact form 7 hidden country field

Effortlessly incorporate a hidden location field into CF7. The user's location will be automatically included upon form submission, eliminating the need for the user to manually fill in the location.

If you wish to incorporate the user’s location on Contact Form 7 forms using If-So’s geolocation service, you can follow these two simple steps:

  1. Ensure that If-So is installed on your website.
  2. In your Contact Form 7 form, add the following code to the form tab, placing it wherever you prefer.
[hidden country class:country-field]
<span class="country-shortcode" style="display: none;">
  [ifsoDKI type='geo' show='country']
</span>

Refer to the screenshot below for an example of the code added to CF7:

Contact Form 7 hidden country field
  1. On the page where you embed your Contact Form 7 form, include the following code within an HTML block, element, or mode:
<script>
  document.addEventListener('DOMContentLoaded', () => {
    let field = document.querySelector('.country-field')
    let shortcode = document.querySelector('.country-shortcode')
    field.value = shortcode.textContent.trim()
    shortcode.remove()
  })
</script>

Categories

Topic

Contact, Support

Conditions

Geolocation

Realated templates and examples