I have two fields, a select list of checkboxes and a taxonomy term reference. I would like the taxonomy term reference to be optional unless one of the checkboxes has a certain value, in which case a value must be entered into the taxonomy term reference field.

Is there a module that can accomplish this? I tried the Field Validation module but I couldn't find a way to configure it for this use case. Custom code is fine too if you could point me in the right direction.

1 Answer 1


With custom code you can do something like this:

add a new validation function using hook_form_alter()

your_module_form_alter($form, $form_state, $form_id) {
  if($form_id == 'the_form_ID') {
    $form['#validate'][] = 'your_custom_validation_function';

then check to see if the conditions are met

function your_custom_validation_function($form, &$form_state){
  if( $form_state['values']['your_checkbox_name'] == 1 ) {
    // check to see if tags are set
    // use form_set_error('tags_field_id', 'error message') to set a error message

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.