You are here

function makemeeting_answers_form_validate in Make Meeting Scheduler 7.2

Form validate: validate answers

File

./makemeeting.form.inc, line 139

Code

function makemeeting_answers_form_validate($form, &$form_state) {

  // The required attribute won't work, so we display a single message
  if (!$form_state['values']['name']) {
    drupal_set_message(t('You must enter your name.'), 'error');
  }

  // Check is the user has already voted
  if (user_is_logged_in() && empty($form_state['values']['answer_edited'])) {
    global $user;
    $select = db_select('makemeeting_answers', 'ma');
    foreach ([
      'field_name',
      'entity_type',
      'deleted',
      'entity_id',
      'language',
      'delta',
    ] as $info) {
      $select
        ->condition($info, $form_state['values'][$info]);
    }
    $result = $select
      ->condition('uid', $user->uid)
      ->countQuery()
      ->execute()
      ->fetchField();
    if ($result) {
      form_error($form, t('You already voted on this poll.'));
    }
  }
}