You are here

function webform_validate_unique in Webform 6.3

Same name and namespace in other branches
  1. 7.4 includes/webform.components.inc \webform_validate_unique()
  2. 7.3 includes/webform.components.inc \webform_validate_unique()

Validate an element value is unique with no duplicates in the database.

3 string references to 'webform_validate_unique'
_webform_render_email in components/email.inc
Implements _webform_render_component().
_webform_render_number in components/number.inc
Implements _webform_render_component().
_webform_render_textfield in components/textfield.inc
Implements _webform_render_component().

File

includes/webform.components.inc, line 1033
Webform module component handling.

Code

function webform_validate_unique($element, $form_state) {
  if ($element['#value'] !== '') {
    $nid = $form_state['values']['details']['nid'];
    $sid = empty($form_state['values']['details']['sid']) ? 0 : $form_state['values']['details']['sid'];
    $count = db_result(db_query("SELECT count(*) FROM {webform_submitted_data} WHERE nid = %d AND cid = %d AND sid <> %d AND LOWER(data) = '%s'", $nid, $element['#webform_component']['cid'], $sid, $element['#value']));
    if ($count) {
      form_error($element, t('The value %value has already been submitted once for the %title field. You may have already submitted this form, or you need to use a different value.', array(
        '%value' => $element['#value'],
        '%title' => $element['#title'],
      )));
    }
  }
}