The validation function in the Form API is meant to evaluate the user input and report the errors back to the user if any.
You could change your logic in this way to facilitate your implementation:
- The field _field_title_tag_list_article_ is not required by default
- In the validation function, you would check whether the value of a second field (i.e. _field_validate_titles_) is set to a given value (i.e. _field_validate_titles_ == 'needs validation').
It would look something like this:
if ($form_state['values']['field_validate_titles'] == 'needs validation' &&
form_set_error('field_title_tag_list_article', t('The title tags are required.'));
You could download the Drupal Examples modules and install the _form_example_ module, then check the example number 6.
Advice for new users
In general, I suggest you browse the examples so that you are familiar with this handy reference.
Quite often, you will find that someone else had the same problem before. Sometimes, there is a community contributed module that solves your problem.
In your particular case, the conditional fields module could help you accomplish your goal without having to write a single line of code:
$form['#validate']array, passing the
$formin by reference to the validate function, and altering it there. But even if it does work it's a bit of a hack
#states? Check out lullabot.com/articles/form-api-states