FormItCountryOptions - how to output both country name and ISO code?

Hi!
My website creates musician profiles with Formit, formit2resource (Formit input is written into a database to create resources). I am using FormItCountryOptions snippet to output a dropdown list of countries! The countries are stored in an array in /core/components/formit.includes/us.countries.inc.php in a format:
‘AF’ => ‘Afghanistan’,
‘AL’ => ‘Albania’,

So, you can fill in the form, choose your country from the dropdown and submit it. The snippet allows to optionally save either country names or iso-codes.

I wonder if there’s an easy way to retrieve for displaying on site pages both name and code? So, for example for Afghanistan, I would like to output the results as Afghanistan, AF.

Please advise!
Thanks a lot!

you could use an output - filter like that, to get the country-name from iso-code:

$modelPath = $modx->getOption('formit.core_path', null, $modx->getOption('core_path', null, MODX_CORE_PATH) . 'components/formit/') . 'model/formit/';
$modx->loadClass('FormIt', $modelPath, true, true);

$fi = new FormIt($modx,$scriptProperties);

/** @var fiCountryOptions $co */
$co = $fi->loadModule('fiCountryOptions','countryOptions',$scriptProperties);
$co->initialize();
$co->getData();
$countries = $co->countries;

if (!empty($input) && array_key_exists($input, $countries)){
    return $countries[$input];
}

return '';

Thank you, Bruno. My php is helpless. Can you please provide an example of how to output the country name? This is a snippet. I can save it and name something. Then I need to call it in my chunk… and what happens? I don’t get it :frowning:

if you have a placeholder for outputing the country, lets say, named [[+country]]
you can use that snippet as output-filter like that:

[[+country:fiCountryOptionsGetCountry]]

if you have named that snippet fiCountryOptionsGetCountry

1 Like

That simple :slight_smile: !!! Works. Thank you!

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.