You are here

function ctools_context_user_settings_form_validate in Chaos Tool Suite (ctools) 6

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

Validate a user.

1 string reference to 'ctools_context_user_settings_form_validate'
user.inc in plugins/contexts/user.inc
Plugin to provide a user context

File

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

Code

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

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