I have contact.module installed and enabled on my site.
However, when the user registers, "contact" data field is not set in users table. Hence, in order to be contacted by other users, my users have to go to "Edit my settings" and check "Other users can contact me" checkbox. I want it to be enabled by default.

Can anyone recommend me a way to set that "contact" data field to 1 at registration? Figuring it out requires quite a bit of digging through Drupal's code.

Unfortunately, power and flexibility of Drupal comes at a price that it is hard to map a given site page to a module function.

Thanks.
Sergei

Comments

dtabach’s picture

I also would like to turn on contact forms by default, keeping the option to turn it off if an user wants so.

Durval Tabach

dtabach’s picture

Just found this topic: http://drupal.org/node/32291
And this comment seems to answer our question. I'll test it right now.

Durval Tabach

drupalguest’s picture

Edit contact.module.

Find function contact_user

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

=====
Sony PSP (1.8gb)---New Ipod NANO (4gb)---New XBOX 360 (20gb)

dtabach’s picture

I've just tested it. 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 again.

- Users that have the contact form disabled prior to the contact.module change 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.

So, I'm still looking for a solution.

Durval Tabach

che_guevara’s picture

The right hackish solution in the same place will probably be

if(defined edit['contact'])
... 'contact', 1, $edit['contact']
else
... 'contact', 1, 1

Besides, I will need do similar check in another, for the case when someone wants to contact this user.

What I want to do is during user's registration, stick 'contact' data value 1 into database. Where should I add the code?
Thanks

moshe weitzman’s picture

this begs for an admin preference. noone will be agree on whether this should be on or off by default. it varies depending on your site.

telex4’s picture

Agreed, an admin setting is a must.

Also, I've made the change so that, upon editing their account users will automatically have the contact form on. But with over 480 registered users who aren't going to go and look at their settings page that's not much use. How can we quickly set the variable to 'on' for everyone? I had a look at the database directly and it seems tied up in the 'data' longtext field, something I don't particularly want to fiddle with.

telex4’s picture

Bump... anyone know how to do this?

scoonz’s picture

First of all apply this:

http://drupal.org/node/32291#comment-67961

Then if you have a lot of registered users and want to update their information also, you have to write a PHP script that will do the following for every user: extract 'data' field as array from 'users' table, add new element ($data['contact'] = 1) and push it back.

This will check this box 'ON' for every user WITHOUT deprivation his right to uncheck it later.

--
Thanks, Drupal !
Music demos online

bigbman’s picture

this sets the registration form to default allow others to contact you:

<?php
function contact_user($type, $edit, &$user, $category = NULL) {

if ($type == 'register')
{
return array(array('title' => t('Contact settings'), 'data' => form_checkbox(t('Personal contact form'), 'contact', 1, 1, t('Allow other users to contact you by e-mail via your personal contact form. Note that your e-mail address is not made public and that privileged users such as site administrators are able to contact you even if you choose not to enable this feature.', array('%url' => "user/$user->uid/contact"))), 'weight' => 2));
}
else if ($type == 'form' && $category == 'account')
{
return array(array('title' => t('Contact settings'), 'data' => form_checkbox(t('Personal contact form'), 'contact', 1, $edit['contact'], t('Allow other users to contact you by e-mail via your personal contact form. Note that your e-mail address is not made public and that privileged users such as site administrators are able to contact you even if you choose not to enable this feature.', array('%url' => "user/$user->uid/contact"))), 'weight' => 2));
}
else if ($type == 'validate')
{
return array('contact' => $edit['contact']);
}
}
%>