You are here

function custom_admin_filter_validate in Spam 5.3

Be sure that the custom filter is valid.

File

filters/custom/custom.module, line 367

Code

function custom_admin_filter_validate($form_id, $form_values) {
  if ($form_values['style'] == SPAM_CUSTOM_STYLE_REGEX) {
    if (preg_match($form_values['filter'], 'test') === FALSE) {
      form_set_error('filter', t('Failed to validate your filter\'s regular expression.  It must be properly formatted as a <a href="http://www.php.net/manual/en/ref.pcre.php">Perl-compatible regular expression</a>.  Review the above error for details on the specific problem with your expression.'));
    }
  }
  if (isset($form_values['cid'])) {

    // update
    $cid = db_result(db_query("SELECT cid FROM {spam_custom} WHERE filter = '%s' AND cid != %d", $form_values['filter'], $form_values['cid']));
    if ($cid) {
      form_set_error($cid, t('Custom filter %filter already exists', array(
        '%filter' => $form_values['filter'],
      )));
    }
  }
  else {

    // create
    $cid = db_result(db_query("SELECT cid FROM {spam_custom} WHERE filter = '%s'", $form_values['filter']));
    if ($cid) {
      form_set_error($cid, t('Custom filter %filter already exists', array(
        '%filter' => $form_values['filter'],
      )));
    }
  }
}