We are using the Countries module to provide country fields where editors can choose a country and it gets displayed in the frontend. Which works absolutely fine.
But we want to fill that field programmatically through a custom module. No matter what value we provide to fill the field (country name, ISO 2 code etc.) the field doesn't get populated.
We are certainly sure that there is no any error somewhere else as we are filling multiple fields in our module and all are working as expected.
We want to know in which format does the country field expect the value to be?
Clarification:
We have a field field_country
in profile2 with the Country
type coming through Countries module. We are getting input in our module through following code in our form:
include_once DRUPAL_ROOT . '/includes/iso.inc';
include_once DRUPAL_ROOT . '/includes/locale.inc';
$form['country'] = array(
'#title' => t('Country'),
'#type' => 'select',
'#description' => t('Please Select Your Country Where Do You Belong To.'),
'#required' => 'true',
'#options' => array('' => t('-Select a Country-')) + country_get_list(),
'#default_value' => isset($values['country']) ? $values['country'] : '',
);
We have also tried '#type' => 'country'
and a few other things but same result.
For submitting this value we are using the code:
$profile->field_country['LANGUAGE_NONE'][0]['value'] = $data;
country_get_list()
function ?