I am using a custom field in the profile2 module for when a user registers. The field is a Boolean field using the radio button widget.
I want to programmatically set the value for the field using hook_form_alter().
I have managed to successfully set the #default_value using:
function mymodule_form_user_register_form_alter(&$form, &$form_state) {
$form['profile_company']['field_employees']['und'][0]['value']['#default_value'] = 0;
}
But this code does not actually check the No button, so it looks like nothing has been selected and when the form is submitted it throws an error saying that that field is required and nothing has been selected.
How can I get the code to actually check one of the buttons as well as setting the default value, based on values that I want to pre-fill the form with?
The code above would work fine with a text field, It just doesn't work with a Boolean field using radio buttons.
I have spent a while on this and can't seem to find an answer. I thought maybe I need to use the field #after_build property or possibly JavaScript?
I'm attaching a screen grab of my field settings.