The title says all.

I attached files contact.module and contact.pages.inc.

for newbies: they are in .txt format because attachment of .inc and .module files arent allowed...just rename the file

I didn't check out how to use patch because im pressed for time to finish the site, but thought it would be useful for people out there who want this feature and i think it could be included in future releases... the only 'dirty' part of the code was that when an anonymous user uses the personal contact form, in drupal_mail i used 'page_mail' as they key parameter instead of 'user_mail' .. maybe this issue can be sorted by adding 'user_mail_anon' for e.g. to make the code neither..

tellah:)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

davbusu’s picture

forgot to mention.. i used 'page_mail' so when the email is sent it, rather then receiving:

testuser1,

(http://www.example.com/index.php?q=user/) has sent you a message via your contact form (http://www.example.com/index.php?q=user/3/contact) at Example Site.

If you don't want to receive such e-mails, you can change your settings at http://www.example.com/index.php?q=user/3.

Message:

test

one would receive:

Mister X sent a message using the contact form at http://www.example.com/index.php?q=user/3/contact.

test

davbusu’s picture

the issue to be solved at stated is to create a function for e.g. user_mail_anon which basically is the same as page_mail but this part would also appear:

If you don't want to receive such e-mails, you can change your settings at http://www.example.com/index.php?q=user/3.

Message:

Also it would be great if the url is enclosed in brackets like in user_mail to have more consistency

davbusu’s picture

ok i managed to do it...find attached new contact.module and contact.pages.inc

I added key user_mail_anon which is basically the same as user_mail but doesn't displays user's page (user/0)..here is an example of the received email:

testuser1,

Mister X has sent you a message via your contact form (http://www.example.com/index.php?q=user/3/contact) at Example Site.

If you don't want to receive such e-mails, you can change your settings at http://www.example.com/index.php?q=user/3.

Message:

Test 1 1 1323

furthermore i modified a bit page_mail so it displays subject as [SITENAME/CATEGORY] SUBJECT rather then [CATEGORY] SUBJECT and the content of the mail is of the format:

Mister X sent a message using the contact form (http://www.example.com/index.php?q=contact) at Example Site.

Dave Reid’s picture

Status: Needs review » Closed (duplicate)

Please post your 6.x patches in this issue #58224: Allow anonymous users access to a members personal contact form. Also note there is the Anonymous Contact module that could use help being ported to 6.x since it is unlikely this issue will be something backported to 6.x from HEAD.

roderik’s picture

Version: 6.6 » 6.13
FileSize
8.48 KB

Hey, I know something.... How about posting 6.x patches here and not in #58224: Allow anonymous users access to a members personal contact form?

That way the people in #58224 won't have to complain about the D6 patches obstructing D7 development. And I bet we won't confuse the testing robot either.

I did look in #58224 for patches, took the files posted in comment #193, incorporated two changes from the patch in #148
(fixed the watchdog message; made a separate form validate function) and modified things so it applies cleanly to Drupal 6.13 again. So this should work for some people who want to patch the newest D6 instead of using the contact_anon module.

jurgenhaas’s picture

Great idea, I'll give it a try and report back on it here.

jurgenhaas’s picture

Perfect work.

I've downloaded and applied the patch, adjusted the permissions for anonymous users and I got the personal contact links and forms straight away. Just exactly what was required.

I wonder if that could make it's way into 6.x core?

binford2k’s picture

This patch doesn't seem to help. I get this message:

"You need to provide a valid e-mail address to contact other users. Please update your user information and try again."

and nothing I do seems to change it. I'm actually quite flummoxed right now.

roderik’s picture

@jurgenhaas: This topic has been beaten to death, and there's hardly any possibility it will get included into D6 core. (I believe most people were against it because it would open up too much possibility for people to spam your site users. But there may have been other reasons - I didn't read up on every detail.)

So it looks like the faith of this patch is to live forever in this thread marked 'duplicate', until it eventually dies out along with D6 installations, a few years from now. I know no better place for it.

@binford2k: it looks like you can only get that message when you are logged on already, i.e. not an anonymous user. (In which case the patch does not have any effect; you should also get that same message without having patched the module.)
And it looks like you need to need to check your account settings to see that you really have specified a valid e-mail address. If your e-mail address IS valid... I have no clue what's going on.

binford2k’s picture

No, the anonymous user gets this error message. Works fine for the authenticated user. Without this patch, the anonymous user gets the usual auth error.

roderik’s picture

I don't know what to tell you without more info (and don't really know what info to ask for, to be able to trace the error). It works for me...

Damien Tournoud’s picture

Status: Closed (duplicate) » Closed (won't fix)

Drupal 6 is feature frozen.

binford2k’s picture

I don't understand it. Here is my contact_user_page function:

function contact_user_page($account) {
  global $user;
die;
  if ($user->uid && !valid_email_address($user->mail)) {
    $output = t('You need to provide a valid e-mail address to contact other users. Please update your <a href="@url">user information</a> and try again.', array('@url' => url("user/$user->uid/edit")));
  }
  else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
    $output = t('You cannot contact more than %number users per hour. Please try again later.', array('%number' => variable_get('contact_hourly_threshold', 3)));
  }
  else {
    drupal_set_title(check_plain($account->name));
    $output = drupal_get_form('contact_mail_user', $account);
  }

  return $output;
}

With that die in there, it should crap itself on every run. Yet it has absolutely no effect. If I change the contact_mail_user function just a few lines down in the file, it's reflected immediately.

It's like contact_user_page isn't being called at all; or it's being cached in a really weird way. Anyone know what's going on?

binford2k’s picture

Tracked down the problem. Realname conflicts. Hack patch below:

--- realname.module.orig	2009-07-17 02:13:31.000000000 -0700
+++ realname.module	2009-07-17 02:13:44.000000000 -0700
@@ -206,7 +206,7 @@
 function realname_contact_user($account) {
   global $user;
 
-  if (!valid_email_address($user->mail)) {
+  if ($user->uid && !valid_email_address($user->mail)) {
     $output = t('You need to provide a valid e-mail address to contact other users. Please update your <a href="@url">user information</a> and try again.', array('@url' => url("user/$user->uid/edit")));
   }
   else if (!flood_is_allowed('contact', variable_get('contact_hourly_threshold', 3))) {
mariusz.slonina’s picture

#5 patch works ok, thank You:)

NickTech’s picture

I would very much like to use the patch from #5 but I too have RealName module installed. Every time I try using the hack patch from #14 I get the error: **** malformed patch at line 5: function realname_contact_user($account) {

Could someone point me in the right direction?

Thanks!

binford2k’s picture

Just do it by hand. Go to line #206 and find the text if (!valid_email_address($user->mail)) {

Replace it with if ($user->uid && !valid_email_address($user->mail)) {

Btw, the first line wasn't actually part of the patch, it was the command I used to generate it. I'll go edit that post and fix it!

marcushenningsen’s picture

Sorry for being a newbie, I don't understand which file I need to patch against.

Chad_Dupuis’s picture

#5 no longer applies to the latest d6 (6.15 at this point) - looks like some changes in how they show the form to users. Anyone have an updated version? I'm working on it but if someone is done already that would be helpful....
(This might be #10's problem?)

UPDATE - the patch fails because of the commit in 6.15 from http://drupal.org/node/525504. The majority of the patch is fine except for the section that controls contact tab access:

@@ -118,9 +118,9 @@
$account->contact = FALSE;
}
return
- $account && $user->uid &&
+ $account &&
(
- ($user->uid != $account->uid && $account->contact) ||
+ (user_access('access personal contact form') && ($user->uid != $account->
uid) && $account->contact) ||
user_access('administer users')
);
}

This should now add the following section:

+ // Anonymous users can access the contact form with proper permissions
+ if (user_access('access personal contact form')) {
+ return TRUE;
+ }

as the first if statement under

function _contact_user_tab_access($account) {
global $user;

and before
// Anonymous users cannot use or have contact forms.
if (!$user->uid || !$account->uid) {
return FALSE;
}

If this seems correct and someone can roll a new patch with this it would be great. I would but I have other changes in my contact module that I don't want to accidentally incorporate into the patch....

roderik’s picture

Oh. Right. Forgot about this. Well, here's a diff between d6.15 and my current working tree... Seems OK.

Dave Reid’s picture

I'll be putting this feature backport into http://drupal.org/project/contact.

Marticus’s picture

Thank you. I just finished hacking a backport from the D7 version of this thread, but I'm glad to see something being done for those who aren't as techno savvy. Thanks for the correction on the d7 thread, dave and roderik. I'll try to find d6 threads and reply to them hence forth so as to not hinder d7 development. Again, thanks for the prompt solutions.

crikeymiles’s picture

FileSize
7.6 KB

Hi roderik,

This patch seems to work fine against 6.16 as well, although I patched contact, duplicated it, and renamed every 'contact_' to 'contact_anonymous_' and every 'contact. to 'contact_anonymous.' so I could separate the patched module, and update to core at any time without losing the changes. Of course, I don't know what will happen if I have both enabled, as they share menu item, so I don't!

Thanks for your patch, it works great.

jvieille’s picture

This module does not work for me.
I get the new permission, but
1) I get database errors when switching from core "contact" to the new "contact _anonymous"
2) the Views field "Link to contact page" has gone

Side question:
What is the difference between this module and this one?
http://drupal.org/project/contact/

Thanks

Gold’s picture

Damn. Hopefully I've not stepped on anyones toes with this.

I've just contributed a module to do this. It's quick and dirty and could do with a decent amount of enhancement but it scratched the itch my client had and didn't require hacking core files.

http://drupal.org/project/anonymous_contact

If people want to add to this project I'm happy to offer cvs access for a couple of co-maintainers.

feltwebel’s picture

#23 works perfectly for drupal 6.19. Thanks.

vcrkid’s picture

I am also using 6.19 but #23 doesn't work for me and I'm not sure why (and I'd really really really like it to work for me).

I get the following error:

* warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'contact_mail_user' was given in /drupal/includes/form.inc on line 376.
* recoverable fatal error: Object of class stdClass could not be converted to string in /drupal/includes/form.inc on line 2126.

Any help would be very appreciated :-)

manoloka’s picture

Not sure what shall I do with #23

Substitute it from the modules/contact or only add it to that folder?

or shall I add it like any other contributed module?

Thanks

jvieille’s picture

sean porter’s picture

#23 worked for me, running 6.22

I think from an amateur developer point of view its a bit more elegant than #25 because it uses the standard contact form found in user's profile pages.

I do, however, miss the view's links - not sure why those went away, but it appears as though the "User: link to contact form" is missing from the User fields... any way to add this back in?

Thanks,