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.
Contact form 7 hidden country field

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

Contact US

life-ring Support Hours: Monday - Friday, - ()
Displaying Support Hours in Your Users' Local Time

Your Country Flag

Visitor's Country Flag (shortcode)
Urgency-Driven Countdowns
🕐 Our next webinar

25.10 | 17:00 UTC

according to your time zone (Unknown)

Timezone-Sensitive Event Time Display