FormItCountryOptions
Last updated Oct 7th, 2020 | Page history | Improve this page | Report an issue
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
Budget
$301 per month—let's make that $500!
Learn moreWhat 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¶
- FormIt.Hooks
- FormIt.Validators
- FormIt.FormItRetriever
- FormIt.Tutorials and Examples
- FormIt.FormItCountryOptions
- 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
Budget
$301 per month—let's make that $500!
Learn more