Jump to main content Jump to doc navigation

What is FormItCountryOptions?

FormItCountryOptions is an assistance snippet for FormIt 1.7.0+ that will output an option list of countries in the world. It is useful for forms that need a dropdown list of countries.

Usage

Simply add the Snippet to your form, inside a <select> element:

<select name="country">
    [[!FormItCountryOptions? &selected=`[[!+fi.country]]`]]
</select>

Note how we are passing the value of the "fi.country" placeholder (which stores the value of the country field) into the selected parameter. This tells FormItCountryOptions to select the last-selected option in the form.

FormItCountryOptions Properties

FormItCountryOptions comes with some default properties you can override. They are:

Name Description Default
selected The country value to select.
selectedAttribute Optional. The HTML attribute to add to a selected country. selected="selected"
tpl Optional. The chunk to use for each country dropdown option.
useIsoCode If 1, will use the ISO country code for the value. If 0, will use the country name. 1
prioritized Optional. A comma-separated list of ISO codes for countries that will move them into a prioritized "Frequent Visitors" group at the top of the dropdown. This can be used for your commonly-selected countries.
prioritizedGroupText Optional. If set and &prioritized is in use, will be the text label for the prioritized option group.
allGroupText Optional. If set and &prioritized is in use, will be the text label for the all other countries option group.
optGroupTpl Optional. If set and &prioritized is in use, will be the chunk tpl to use for the option group markup. optgroup
toPlaceholder Optional. Use this to set the output to a placeholder instead of outputting directly.

Prioritizing Countries

Sometimes you want to have certain countries appear at the top of the list, in an option group. FormItCountryOptions supports this, with the &prioritized option. For example:

[[!FormItCountryOptions?
    &selected=`[[+fi.country]]`
    &prioritized=`US,GB,DE,RU,JP,FR,NL,CA,AU,UA`
]]

Will output a list that looks like this:

You simply pass the ISO codes of the countries you wish to prioritize in the &prioritized parameter. You can also adjust the text of the option groups with the &prioritizedGroupText and &allGroupText properties.

See Also

  1. FormIt.Hooks
    1. FormIt.Hooks.email
    2. FormIt.Hooks.FormItAutoResponder
    3. FormIt.Hooks.math
    4. FormIt.Hooks.recaptcha
    5. FormIt.Hooks.redirect
    6. FormIt.Hooks.spam
    7. FormIt.Hooks.FormItSaveForm
  2. FormIt.Validators
  3. FormIt.FormItRetriever
  4. FormIt.Tutorials and Examples
    1. FormIt.Examples.Custom Hook
    2. FormIt.Examples.Simple Contact Page
    3. FormIt.Handling Selects, Checkboxes and Radios
    4. FormIt.Using a Blank NoSpam Field
  5. FormIt.FormItCountryOptions
  6. FormIt.FormItStateOptions

Support the team building MODX with a monthly donation.

The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.

Backers

  • modmore
  • STERC
  • Digital Penguin
  • Jens Wittmann – Gestaltung & Entwicklung
  • Fabian Christen
  • Dannevang Digital
  • Sepia River Studios
  • CrewMark
  • Chris Fickling
  • deJaya
  • eydolan
  • Following Sea
  • Lefthandmedia
  • Murray Wood
  • Anton Tarasov
  • Stéphane Jäggi
  • Raffy
  • Snow Creative
  • A. Moreno
  • Nick Clark
  • JT Skaggs
  • Helen
  • YJ
  • krisznet
  • Richard
  • Yanni

Budget

$311 per month—let's make that $500!

Learn more