I have a form created from php with FormField and i have the country field, which contains a list of countries. My question is how can i set a country to be selected, from php and not from html templates ( cause it's created as {form_field field=$field} in the tpl file ).
Here is my code:
$countries = Country::getCountries($this->context->language->id);
$format['country'] = (new FormField)
->setName('country')
->setType('countrySelect')
->setLabel(
$this->translator->trans(
'Country', [], 'Shop.Forms.Labels'
)
)
->setRequired(true)
;
foreach ($countries as $country) {
$format['country']->addAvailableValue(
$country['id_country'],
$country['country']
);
}
If i could set it from php it would be awesome, cause i don't want to change core files or something. Thanks in advance.