You are here

function honeypot_admin_form_validate in Honeypot 7

Same name and namespace in other branches
  1. 6 honeypot.admin.inc \honeypot_admin_form_validate()

Validate the admin form.

File

./honeypot.admin.inc, line 172
Honeypot administration forms.

Code

function honeypot_admin_form_validate($form, &$form_state) {

  // Make sure the time limit is a positive integer or 0.
  $time_limit = $form_state['values']['honeypot_time_limit'];
  if (is_numeric($time_limit) && $time_limit > 0 || $time_limit === '0') {
    if (ctype_digit($time_limit)) {

      // Good to go.
    }
    else {
      form_set_error('honeypot_time_limit', t("The time limit must be a positive integer or 0."));
    }
  }
  else {
    form_set_error('honeypot_time_limit', t("The time limit must be a positive integer or 0."));
  }

  // Make sure Honeypot element name only contains A-Z, 0-9.
  if (!preg_match("/^[-_a-zA-Z0-9]+\$/", $form_state['values']['honeypot_element_name'])) {
    form_set_error('honeypot_element_name', t("The element name cannot contain spaces or other special characters."));
  }

  // Make sure Honeypot element name starts with a letter.
  if (!preg_match("/^[a-zA-Z].+\$/", $form_state['values']['honeypot_element_name'])) {
    form_set_error('honeypot_element_name', t("The element name must start with a letter."));
  }

  // Make sure Honeypot element name isn't one of the reserved names.
  $reserved_element_names = array(
    'name',
    'pass',
    'website',
  );
  if (in_array($form_state['values']['honeypot_element_name'], $reserved_element_names)) {
    form_set_error('honeypot_element_name', t("The element name cannot match one of the common Drupal form field names (e.g. @names).", array(
      '@names' => implode(', ', $reserved_element_names),
    )));
  }
}