Hello,
Would this module work on protecting contact forms? I could really use a module like this that would block any messages sent that contain links.

Comments

espirates’s picture

+subscribe

pieterdc’s picture

Right now, it doesn't work on contact forms. It only works on comment forms.

yngens’s picture

Title: Does it work on contact forms? » Please make Block anonymous links module to work with contact forms
Category: support » feature

With your permission I have changed the title and category of the issue. Since the module is working just fine with comment forms, it should not be much problematic to expand it to work with contact forms too. Thanks!

Ivan Simonov’s picture

Issue summary: View changes

Just add next code to module file (7.x):

function blockanonymouslinks_form_alter(&$form, &$form_state, $form_id) {
  if (($form_id == 'contact_site_form') || ($form_id == 'contact_personal_form')){
    $form['#validate'][] = 'blockanonymouslinks_contact_form_validate';
  }
} 

/**
 * Validate the message and subject.
 */
function blockanonymouslinks_contact_form_validate($form, &$form_state) {
  global $user;

  //check if anonymous user
  if (!$user->uid) {
    $comment = $form_state['values']['message'] . ' ' . $form_state['values']['subject'];
    if (preg_match("@(http://|https://|ftp://|mailto:|smb://|afp://|file://|gopher://|news://|ssl://|sslv2://|sslv3://|tls://|tcp://|udp://)+@is", $comment) || preg_match("@(www\.[a-zA-Z0-9\@:%_+*~#?&=.,/;-]*[a-zA-Z0-9\@:%_+~#\&=/;-])+@is", $comment)) {
      form_set_error("comment", t("You have to be logged in to post links. This is an anti-spam measure."));
    }
  }
}