I figured it out on my own: The process is the same as in Drupal 6. The arrays have just changed a bit. To use a custom validation with hook_form_alter()
and a custom validation function, you would load your form_state values as follows (example based on fields from profile2):
function example_validate($form, &$form_state) {
// Store our field values to validate against.
$fieldname = $form_state['values']['profile']['field_name']['und'][0]['value'];
if ($fieldname == null) {
form_set_error('profile][field_name', t('Error Message'));
}
}
The actual value for our fields is now found in the 'und'
array. Since the #parent
property of these profile fields is an array, use 'foo][foo2'
format to specify the element for which to show the validation error. See form_set_error().