I need to show a validation error message when a radio button is clicked but none of the checkbox is checked. The checkbox field is optional in content type. Should be required when radio button is clicked. How can it implement this programaticaly. Not interested to add conditional field module for a single requirement.
2 Answers
In form alter use this code
function my_module_form_alter(&$form, &$form_state, $form_id) {
$radio = $form['#node']->field_radio['und'][0]['value'];
if($radio == 1){//if
$form['field_checkbox']['und']['0']['value']['#required'] = TRUE;
//OR
$form['field_checkbox']['und']['0']['#required'] = TRUE;
}
}
hook_form_alter()