You are here

function ctools_context_user_settings_form_validate in Chaos Tool Suite (ctools) 7

Same name and namespace in other branches
  1. 6 plugins/contexts/user.inc \ctools_context_user_settings_form_validate()

Validate a user.

File

plugins/contexts/user.inc, line 118
Plugin to provide a user context.

Code

function ctools_context_user_settings_form_validate($form, &$form_state) {
  if ($form_state['values']['type'] != 'select') {
    return;
  }

  // Validate the autocomplete.
  if (empty($form_state['values']['uid']) && empty($form_state['values']['user'])) {
    form_error($form['user'], t('You must select a user.'));
    return;
  }
  if (empty($form_state['values']['user'])) {
    return;
  }
  $account = user_load_by_name($form_state['values']['user']);
  if (!$account) {
    form_error($form['user'], t('Invalid user selected.'));
  }
  else {
    form_set_value($form['uid'], $account->uid, $form_state);
  }
}