O
O
Otrivin2017-10-24 15:53:52
PHP
Otrivin, 2017-10-24 15:53:52

How to search for a string by regular expression in an array?

There is a site on Drupal 7, on the site there are several feedback forms, from which a ton of rubbish comes. Tried to install ready-made anti-spam modules - no effect.

I want to try to filter spam by implausible names (in the field "Your name:" is written rubbish in Latin) just before sending it to the mail.

Found in the module the function responsible for sending

$message = drupal_mail('webform', 'submission', $address, $language, $mail_params, $email['from']);
if ($message['result']) {
  $send_count += $send_increment;
}


How to wrap it in a check on the text sent to the email?
You will have to search for a string consisting of "Your name:" and random Latin letters;
Search among the values ​​of the $mail_params array.

I tried this: if the string "Your name: wsdfSDFASds" is not found in the array, then we send an email
if (!array_search(preg_grep('/Ваше имя: ([A-Za-z])*/', $mail_params))){
  $message = drupal_mail('webform', 'submission', $address, $language, $mail_params, $email['from']);
  if ($message['result']) {
    $send_count += $send_increment;
  }
}

But either I incorrectly composed the regular expression, or incorrectly built the code itself; in general, this solution does not work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
afi13, 2017-10-24
@afi13

try https://www.drupal.org/project/honeypot

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question