Log entry
budda - April 7, 2009 - 14:42
| Project: | Author Contact |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
How about logging the message that was sent from the form and to what user via watchdog() ?

#1
I second that, being able monitor the use of the contact form and spot potential abuse of the system is important.
#2
You're right, it's a good idea. This feature is now in the dev version.
#3
#4
Automatically closed -- issue fixed for 2 weeks with no activity.
#5
Hi James,
I have installed the latest 6.x-1.x-dev version -- datestamp = "1247486600", but I can't see the email messages under "Recent log entries" (/admin/reports/dblog)
I do see some email log entries, because I set Devel module to log mails in stead of sending them out. But none from author contact, if I disable and "go live", with actual mails being sent out.
Do you know what's going on, perhaps I need to tweak some settings in Drupal to activate email logging?
Thanks for making a great module!
#6
I couldn't wait, so I found some code in the devel.module, at 1764, which logs email messages in stead of sending them. I tweaked it to log email messages sent via Author Contact -- to start loggin':
Insert this code...
// insert message in Dblog(watchdog), original from devel.module, line 1764watchdog(
'authorcontact',
'Mail sent:<br />To: %to<br />From: %from<br />Subject: %subject<br />Body: %body<br /><br />',
array(
'%to' => $to,
'%from' => $params['senderemail'] . " - " . $params['sendername'],
'%subject' => $params['nodetitle'],
'%body' => $params['sendercomment'],
WATCHDOG_INFO,
)
);
...after line 109 in authorcontact.module:
drupal_set_message(t('Contact sent from @from.', array('@from' => $form_state['values']['senderemail'])));After that you should be able to see the messages sent via Author Contact under "Recent log entries" - /admin/reports/dblog
I am not sure what the process is... Maybe testing it and then including it in the latest dev release if it works?
#7
Hi Ressa
This is already in the dev that I see on cvs checkout - I have the code as follows:
//make watchdog entrywatchdog('mail', 'Author Contact: %name-to was sent an e-mail from %name-from using the form on %page', array('%name-to' => $pageAuthor . " <$to>", '%name-from' => $from, '%page' => $params['referrer']));
Placed before the drupal_set_message
I'll see if I can figure out why it's not in the dev download.
#8
[edit] I found I had committed it to HEAD but not 6.x dev - this should now appear in the next 6.x dev snapshot. [/edit]
By the way - I had decided not to log the actual messages as I think is a privacy concern. As far as I know the normal contact form does not log the message itself.
#9
#10
Beautiful! I think the snapshot just got in, but the latest 6.x dev (6.x-1.x-dev, 2009-Oct-30) is still the old version from 13th of July 2009.
Or do I have to wait a bit more for the latest version?
#11
Hi Ressa, I've just downloaded the 6.x-1.x-dev version marked 30 Oct and at the top of the file it says:
// $Id: authorcontact.module,v 1.6.4.5 2009/10/30 03:21:43 justjamesaus Exp $And it has the latest changes in it. Can you confirm that's how it is for you?
#12
Hi James,
The latest dev version online is now the correct one, from 2009-Oct-30.
There is a flood_register_event in the code, but no flood_is_allowed (which checks if the message limit is reached) so I inserted it two places in the authorcontact.module:
1. In the create block function, where I made two versions. They both alert the user that the message limit is reached, at the top of the form, but 1.2 also prevents the form fields from being shown.
I think I prefer 1.2, since it also makes the flood check in the authorcontact_form_validate function redundant, what do you think?
1.1 Alert user if the message limit is met:
//create block /// NOTE: ORIGINALLY LINE 91$block['subject'] = t('Contact Author');
//alert user if the message limit is met
if (!flood_is_allowed('authorcontact', variable_get('contact_hourly_threshold', 3))) {
$block['content'] = t('<div class="messages status"><em>') . t('You cannot send more than %number messages per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3))) . t('</em></div>');
}
$block['content'] .= t('<div class="authorcontact-desc">') . variable_get('authorcontact_desc', '') . t('</div>');
$block['content'] .= drupal_get_form('authorcontact_form');
return $block;
}
break; /// NOTE: ORIGINALLY LINE 97
1.2 Alert user if the message limit is met AND hide the form:
//create block /// NOTE: ORIGINALLY LINE 91//alert user if the message limit is met AND hide form
if (!flood_is_allowed('authorcontact', variable_get('contact_hourly_threshold', 3))) {
$block['content'] = t('<div class="messages status"><em>') . t('You cannot send more than %number messages per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3))) . t('</em></div>');
return $block;
}
else {
$block['subject'] = t('Contact Author');
$block['content'] = t('<div class="authorcontact-desc">') . variable_get('authorcontact_desc', '') . t('</div>');
$block['content'] .= drupal_get_form('authorcontact_form');
return $block;
}
}
break; /// NOTE: ORIGINALLY LINE 97
2. In the form validation function, which displays a warning at the top of the page. If version 1.2 is used, there is no need for it, since the form isn't being shown anyway.
/**
* Validate the form
*/
function authorcontact_form_validate($form_id, $form_values) {
//check for spamming
if (!flood_is_allowed('authorcontact', variable_get('contact_hourly_threshold', 3))) {
form_set_error('contact_hourly_threshold', t('You cannot send more than %number messages per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3))));
}
//check the email address is valid
if(isset($form_values['values']['senderemail'])) {
if (!valid_email_address($form_values['values']['senderemail'])) {
form_set_error('mail', t('The e-mail address you specified is not valid.'));
}
}
}
#13
Oops, I changed the title, I am changing it back 8o)
#14
Hi Ressa, I've added this in as you've suggested in 1.2 above - although I'm still showing the title and description text for the block as I feel this is needed to give the contact note some context.
Thanks for your attention to this, it's greatly appreciated.
#15
Automatically closed -- issue fixed for 2 weeks with no activity.