Bug with Contact Module in user profiles

Roi Danton - April 10, 2008 - 10:24
Project:Gotcha - Contact Spam Catcher
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

After checking the contact form submission for spam, Gotcha calls the function for the common contact form. So using the "user contact form" (e.g. user/1/contact) Gotcha doesn't allow guests to submit their entries (fatal: No recipient addresses found in message header).

Therefore we rewrote the gotcha module file to allow guests using "user contact forms". Here are the changes between original module file and our modified version (- = deleted, + = added):

--- gotcha.module.orig 2008-02-01 00:42:57.000000000 +0100
+++ gotcha.module 2008-04-09 19:51:44.000000000 +0200
@@ -212,22 +212,23 @@

   $LOG_ALL = variable_get('gotcha_log_email', false);

   // Get the entered information.
   $site_name = variable_get('site_name', 'Drupal');
   switch ($form_id) {
-    case 'contact_mail_page':
+    case 'contact_mail_page': {
       $type = 'site';
       $contact = db_fetch_object(db_query("SELECT * FROM {contact} WHERE cid = %d", $form_values['cid']));
       $recipients = $contact->recipients;
       // Apply filter?
       $sendername = check_plain($form_values['name']);
       $sendermail = $form_values['mail'];
       break;
+    }

-    case 'contact_mail_user':
+    case 'contact_mail_user': {
       $type = 'user';
       $account = user_load(array('uid' => arg(1), 'status' => 1));

       // Prepare all fields:
       $recipients = $account->mail;
//      $from = $user->mail;
@@ -237,13 +238,14 @@

       // Format the subject:
//      $subject = '['. variable_get('site_name', 'Drupal') .'] '. $form_values['subject'];

       // Prepare the body:
//      $body = implode("\n\n", $message);
-    break;
+      break;
+    }
   } // End switch.

   $subject = check_plain($form_values['subject']);
   $body = $form_values['message'];

   // Get the session information.
@@ -271,13 +273,20 @@
     // Finish by redirecting to the "go away" page or page_not_found.
     $dest = variable_get('gotcha_goaway_page', variable_get('site_404', 'node'));
     drupal_goto($dest);
   }
   else {
     // Looks okay, so send it on to Contact.
-    contact_mail_page_submit($form_id, $form_values);
+    switch ($form_id) {
+      case 'contact_mail_page':
+        contact_mail_page_submit($form_id, $form_values);
+        break;
+      case 'contact_mail_user':
+        contact_mail_user_submit($form_id, $form_values);
+        break;
+    }
   }
}

/*
  * Implementation of Spam module call for delete contact processing.
  */

Regards,
Roi

#1

NancyDru - April 12, 2008 - 16:52

Hmm, I wonder how it worked for me...

BTW, the PHP manual does not show curly brackets on case statements. But I see what you're doing at the end and it makes sense. I will look at adding it in.

#2

Roi Danton - April 20, 2008 - 20:58

Thanks for that!

BTW, the PHP manual does not show curly brackets on case statements

PHP manual: http://de3.php.net/manual/en/language.control-structures.php

Statements usually end with a semicolon. In addition, statements can be grouped into a statement-group by encapsulating a group of statements with curly braces.

case expr : statement

 
 

Drupal is a registered trademark of Dries Buytaert.