You are here

function advpoll_electoral_list_form_validate in Advanced Poll 5

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

Validate changes to the electoral list.

File

./advpoll.module, line 978
Advanced Poll - a sophisticated polling module for voting, elections, and group decision-making.

Code

function advpoll_electoral_list_form_validate($form_id, $form_values) {
  if ($form_values['op'] == t('Clear electoral list')) {
    if (user_access('administer polls')) {
      db_query('DELETE FROM {advpoll_electoral_list} WHERE nid = %d', $form_values['nid']);
      drupal_set_message(t('Electoral list cleared.'));
      return;
    }
  }
  $add_user = $form_values['electoral_list']['add_user'];
  if ($add_user) {

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