You are here

function advpoll_electoral_list_form_validate in Advanced Poll 7.2

Same name and namespace in other branches
  1. 5 advpoll.module \advpoll_electoral_list_form_validate()
  2. 6.3 advpoll.module \advpoll_electoral_list_form_validate()
  3. 6 advpoll.module \advpoll_electoral_list_form_validate()
  4. 6.2 advpoll.module \advpoll_electoral_list_form_validate()
  5. 7.3 includes/advpoll.pages.inc \advpoll_electoral_list_form_validate()
  6. 7 includes/advpoll.pages.inc \advpoll_electoral_list_form_validate()

Validate changes to the electoral list.

File

includes/advpoll.pages.inc, line 285

Code

function advpoll_electoral_list_form_validate($form, &$form_state) {
  if ($form_state['values']['op'] == t('Clear electoral list')) {
    if (user_access('administer polls')) {
      $nid = $form_state['values']['nid'];
      $items_deleted = db_delete('advpoll_electoral_list')
        ->condition('nid', $nid)
        ->execute();
      drupal_set_message(t('@items cleared from the Electoral list.', array(
        '@items' => $items_deleted,
      )));
      return;
    }
  }
  $add_user = $form_state['values']['electoral_list']['add_user'];
  if ($add_user) {

    // Check that the user exists
    $result = db_query("SELECT uid FROM {users} WHERE name = :name", array(
      ':name' => $add_user,
    ));
    if (!$result) {
      form_set_error('electoral_list][add_user', t('User %user does not exist.', array(
        '%user' => $add_user,
      )));
      return FALSE;
    }
  }
}