Hi,

I am trying to update the appropriate module to allow users to who register for my site to automatically have the personal contact settings set so that they can send and recieve emails via the contact forms. I am new to Drupal and could really use a hand in getting sent in the right direction with this. I am not quite sure where I need make these updates. I have made tweaks on other modules to do other things so I understand the general structure etc. However, I am trying to figure out where I could trigger a change to the registration process that would auto-enable contact settings. Any suggestions would be wonderful and greatly appreciated!!!

My other thoughts were to create some sort of backend job to enable them on a cron but I figured I would try the more traditional approach first before resorted to a hack on the database.

Any help is greatly appreciated!

Thanks,
Frank

Comments

averageyoungman’s picture

That you can do this via the template engine or the contact.module itself. To do it via the module itself, you would need to add the code to handle the databse updates. In your case, and since it sounds like you will be doing this upon registration, you will have to add an if() statement to "function contact_user". This if() statement will need to handle the case "insert" in the same manner that the two for "form" and "validate" do. The contact_user function is called via drupal's hook_user when a user is registered with the case "insert" for the parameter "$type", so you will be able to perform your updates there.

You could also do it by adding a custom function to the phptemplate engine - if you are using that engine - but you can't use the hooks there - I think - as only themeable functions can be overridden. I may be wrong there, but I am 99% sure that's the case. So, in the actual contact.module you would add the following to the contact_user function:

if ($type == 'insert') {
  code for updating DB here;
}

The user info is passed by reference into that function via the "&$user" parameter. you may also want to check the value of the "$category" parameter, as it may or may not be relevant to what you want to do. I don't use that module so I haven't worked with it much.

Hope that helps.

-- aym

kbahey’s picture

If you want all users to have it on by default, then do this.

Edit contact.module.

Find function contact_user

Change
'contact', 1, $edit['contact']
To
'contact', 1, 1

That should do it.

--
Drupal development and customization: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

averageyoungman’s picture

For setting it straight.

-- aym

kbahey’s picture

Actually, now that I think of it, this may not work.
It will work if the user edits their account, but don't think it would work if they never visit it.

--
Drupal development and customization: 2bits.com
Personal: Baheyeldin.com

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

dtabach’s picture

It seems to turn contact forms on by default, but...

- There's no way to turn them off anymore. If users uncheck 'Personal contact form' and then save changes, when visiting the edit account page again the box will be checked, as if it was not modified.

- Users that have the contact form disabled prior to the contact.module change you suggested won't be able to turn it on, although it shows ON in his account settings.

Thus, this solution will only fit for new sites where ALL users must be ALWAYS available for contact. And even in these cases, as the option to turn contacts on/off is still available (although not working), it may lead to confusion.

Durval Tabach

firedancer5’s picture

Thanks you all for your help!! Is greatly appreciated!

Based on your feedback it sounds like I can turn the contacts forms "on" by default as mentioned but then I would have to somehow get rid of the hook that makes the user see the "contact settings" option on the profile page to avoid the confusion mentioned by dtabach. I really do not want users to have the option to be able to turn "off" contact forms so I am fine with removing the option from the account settings. So would that be possible by just removing a hook in the contact module? What do you guys think?

firedancer5’s picture

I just found the contact settings hook_user() in the contact.module and changed it as follows after reviewing the Drupal module development documentation. I made the the form element into a selected radio button so it cannot be deselected. Here is the updated code for others to use if they want to do the same.

function contact_user($type, $edit, &$user, $category = NULL) {
  if ($type == 'form' && $category == 'account') {
    return array(array('title' => t('Contact Policy'), 'data' => form_radio(t('<b>Accept</b> email contact policy'), 'contact', 1, 1, t('By registering for this site you have given other registered users the right to contact you by e-mail via <a href="/%url">your personal contact form</a> or in response to a post you made on on this site. Note that your e-mail address is not made public but other users and privileged users such as site administrators are able to contact you via email.', array('%url' => "user/$user->uid/contact"))), 'weight' => 2));
  }
  if ($type == 'validate') {
    return array('contact' => $edit['contact']);
  }
}

So users are automatically set to "Accept email contact policy" by default and should discontinue use of the site if they disagree with the sites email contact policy terms.

Rezzo’s picture

It's no good thing to modify core modules directly, I guess... but I found a way to activate the personal contact form ONLY at the time a new user registers. And once registered, users can disable the option.

In user.module (drupal 4.6.3) at line 186 you can see this foreach cicle:

    foreach ($array as $key => $value) {
      if ((substr($key, 0, 4) !== 'auth') && (!in_array($key, $user_fields)) && ($value !== null)) {
        $data[$key] = $value;
      }
    }

After that I added this piece:

    if ( !isset($data['contact']) ) {
    	// enable personal contact form as user register
    	$data['contact'] = 1;
    }

Seems working!
And user can disable the function once they modify their profile.

Z2222’s picture

if ( !isset($data['contact']) ) {
    // enable personal contact form as user register
    $data['contact'] = 1;
}

It seems to work well here.

Thanks.

tom_o_t’s picture

Thanks Rezzo, this worked for me in 4.7

DrupNewbie-1’s picture

I have just added that code bit for adding the contact info in 5.2 and it worked perfectly. And I'm not even a developer! Thanks all for adding info.

**Now I need to know how to send a mass email to all "contacts"? Anyone? Bueller???

DN

nikle’s picture

Got it working in 4.7 with the following code after line 205 of user.module

Find
if (strlen($name) > 56) return t('The username %name is too long: it must be less than 56 characters.', array('%name' => theme('placeholder', $name)));
}

and add the following after it

global $user;
return $user->uid == 1;
alexn’s picture

Doesn't that make every user an admin? Looks like a bad bad idea.

iandickson’s picture

messing around with code is way hairy for us non programmers - might break inupdates.

I've put ina feature request - support it with comments and lets get it done properly - maybe the code warriors can post their code their and when the Drupal Gods agree it's safe and correct, we'll have this function asap.

http://drupal.org/node/66648

Ian Dickson - community specialist.

vincent’s picture

Hello,
I know this is a newbie thing...I have tried to install the patch using the patch command but it throws an error:


[sydney:/Sites/fal] vincent% patch -p0 opt_out.patch
can't find file to patch at input line 8
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|Index: contact.module
|===================================================================
|RCS file: /cvs/drupal/drupal/modules/contact.module,v
|retrieving revision 1.36
|diff -u -r1.36 contact.module
|--- contact.module 13 Dec 2005 18:49:47 -0000 1.36
|+++ contact.module 16 Dec 2005 06:01:03 -0000
--------------------------
File to patch: /Sites/fal/modules/contact.module
patching file /Sites/fal/modules/contact.module
Hunk #1 FAILED at 78.
Hunk #2 succeeded at 144 with fuzz 2 (offset 43 lines).
1 out of 2 hunks FAILED -- saving rejects to file /Sites/fal/modules/contact.module.rej


I don't know what to do?? I am using the latest version 4.7.2 but the patch won't apply...Any idea?

alexn’s picture

I believe this is the best current way to do it. This checks to see if the value is "unset," meaning the user hasn't made a choice. The only drawback is that when the user goes to their settings page, it will appear unchecked - but if they submit that page it will be saved as unchecked and they will no longer be contactable. This is acceptable to me for now. I'm sure if I hacked around I could find how to make that box appear checked when there is no setting in the database (as with a new user).

The fix is in modules/contact/contact.module, about line 548. Add the "isset" part to look like this:

else if (isset($account->contact) && $account->contact == 0 && !$admin_access) {
portait’s picture

How do I enable it for all users in Drupal 5.1?

gurukripa’s picture

it wld be nice to enable this for everyone by default. I have a similar need in the Guestbook also :)

anyways..one thing at a time..

later..maybe someone can deactivate..but yes..the danger of not having checkbox shown is bad :(

glass.dimly’s picture

Hey all,

This module might help some of y'all:

http://drupal.org/project/privatemsg

or this one:
http://drupal.org/project/contact_anon

Jeremy

wwwoliondorcom’s picture

How to activate the personal contact form by default

Hi,

I would like all my new members to have the personal contact form activated by default on Drupal 6, do you know how to do ?

Thanks.