You are here

function feedback_mail_form_validate in Feedback 5

Validate the site-wide form submission.

File

./feedback.module, line 369
Enables a site-wide feedback page.

Code

function feedback_mail_form_validate($form_id, &$edit) {
  $page = $edit['page'];
  if (!valid_email_address($edit['mail'])) {
    form_set_error('mail', t('You must enter a valid e-mail address.'));
  }
  if (preg_match("/\r|\n/", $edit['subject'])) {
    form_set_error('subject', t('The subject cannot contain linebreaks.'));
    watchdog('mail', 'Email injection exploit attempted in feedback form subject: ' . check_plain($edit['subject']), WATCHDOG_NOTICE);
  }
  if (!$edit['emailname'] && $page->field_name) {
    form_set_error('emailname', t('Please enter your full name'));
  }
  else {
    if ($page->field_name && drupal_strlen($edit['emailname']) > FEEDBACK_MAX_NAME) {
      form_set_error('emailname', t('Too long input.'));
    }
  }
  if ($page->field_category && (!$edit['category'] || !in_array($edit['category'], _feedback_get_options($page->field_category)))) {
    form_set_error('category', t('Please choose a category'));
  }
  if (!$edit['subject'] && $page->field_subject) {
    form_set_error('subject', t('Please enter a subject'));
  }
  else {
    if ($page->field_subject && drupal_strlen($edit['subject']) > FEEDBACK_MAX_SUBJECT) {
      form_set_error('subject', t('Too long input.'));
    }
  }
  if (!$edit['body'] && $page->field_body) {
    form_set_error('body', t('Please enter your message.'));
  }
  else {
    if ($page->field_body && drupal_strlen($edit['body']) > FEEDBACK_MAX_BODY) {
      form_set_error('body', t('Please shorten your input. Up to !limit characters are allowed.', array(
        '!limit' => FEEDBACK_MAX_BODY,
      )));
    }
  }
  if ($page->field_postal && drupal_strlen($edit['postal']) > FEEDBACK_MAX_POSTAL) {
    form_set_error('postal', t('Please shorten your input. Up to !limit characters are allowed.', array(
      '!limit' => FEEDBACK_MAX_POSTAL,
    )));
  }
  if ($page->field_phone && drupal_strlen($edit['phone']) > 64) {
    form_set_error('phone', t('Too long input.'));
  }
}