You are here

function ctools_context_user_edit_form_settings_form_validate in Chaos Tool Suite (ctools) 7

Validate a node.

File

plugins/contexts/user_edit_form.inc, line 135
Plugin to provide a user_edit_form context.

Code

function ctools_context_user_edit_form_settings_form_validate($form, &$form_state) {

  // 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;
  }
  $uid = $form_state['values']['user'];
  $preg_matches = array();
  $match = preg_match('/\\[id: (\\d+)\\]/', $uid, $preg_matches);
  if (!$match) {
    $match = preg_match('/^id: (\\d+)/', $uid, $preg_matches);
  }
  if ($match) {
    $uid = $preg_matches[1];
  }
  if (is_numeric($uid)) {
    $user = db_query('SELECT uid FROM {users} WHERE uid = :uid', array(
      ':uid' => $uid,
    ))
      ->fetchObject();
  }
  else {
    $user = db_query('SELECT uid FROM {users} WHERE LOWER(name) = LOWER(:name)', array(
      ':name' => $uid,
    ))
      ->fetchObject();
  }
  form_set_value($form['uid'], $user->uid, $form_state);
}