I am creating a community website that has business profiles which are nodes. Each business profile is allowed 3 locations, using the location module. With each location they are allowed to include, among other things, an email address, so if they have multiple locations, they can include a separate email address for each. Because of spammers, and for privacy reasons, I don't want to show the email addresses that the user provides, so I want a contact form. I was using a module called Contact Form On Node but it works with CCK, and since I am allowing 3 email addresses, which are associated with certain locations, I can not use CCK. I have already added a field for email address with the location module, but now I am unsure where to go. Is there a way I can make a custom form, or a function I can create? At this point I am thinking I might just create my own function using PHP, but I have to think that there is a better, easier and more elegant solution. Any help would be much appreciated.

Comments

tryitonce’s picture

Location module is great - but has limitations.

Once you use it and want to use it in different node types for different roles and access permission you are going to be lost.

If the location fields are visible to a role they will always be visible in any other place - i.e. Views, nodes, Blocks. This could look funny as you might get a Views that is not accessible to a particular role, but since they can see the location fields (in general), they will see the location fields in that particular View even if the Views access is limited and excludes this role.

You might be better off not using the location module if you need flexibility in role related access permissions.

I am a bit disappointed by this and hope that location module will resolve this eventually. I will stick with CCK fields for now and use Content Access modules.
There is also an upgrade issue with location module and I have no time to resolve it right now - so I skipped the latest upgrade to 6.x-3.0 (http://drupal.org/node/661274) - it is important to realise that Location module is evolving and that once you created nodes the upgrade might cause problems.

Good luck ...

ryan88’s picture

bump...

So basically, I need to know how to create a contact form in drupal where I can tell it where to send the message to. Right now I just print the email address out, but I want to have a link that leads to a custom contact page. I was trying to use drupal_get_form('contact_mail_user') somehow, but I am not sure where I could supply the email address. I really don't want to have to build a custom form using php to send these, it would be more reliable and look better to somehow be able to use the drupal form. I could use any help you might have.

tryitonce’s picture

I am using just standard Drupal modules.

The basic set-up of Drupal has a contact form. So, if enabled and if the user has agreed to be contacted that would be the standard way.

I don't use anything else for this. But I imagine that there are modules and tutorials available for what you need - search a bit around and also google with Drupal in the search query and you should find a few links.

In case you are getting on a good trail that takes you further - do report back here to help others. I will get back when I stumble over something - though right now I am not looking for any of that.

Good luck ....

ryan88’s picture

Yea, I am using the location module, and I have added an email field. I did this because I have business profiles on the website, and I allow 3 addresses for each profile, and each can have a separate email address, like for different office locations, etc. So I want an contact form for each of those.

ryan88’s picture

I got it to work fairly well after hours of tweaking. I created a view that uses the location id as an exposed filter, and then has the node title and location email address as fields. I then created 2 functions in my template.php file:

function contact_mail_location(&$form_state, $recipient, $title) {
$form['recipient'] = array('#type' => 'value', '#value' => $recipient);
$form['to'] = array('#type' => 'item',
'#title' => t('To'),
'#value' => $title,
);
$form['from_name'] = array('#type' => 'textfield',
'#title' => t('Your Name'),
'#maxlength' => 50,
'#required' => TRUE,
);
$form['from_email'] = array('#type' => 'textfield',
'#title' => t('Your Email'),
'#maxlength' => 50,
'#required' => TRUE,
);
$form['subject'] = array('#type' => 'textfield',
'#title' => t('Subject'),
'#maxlength' => 50,
'#required' => TRUE,
);
$form['message'] = array('#type' => 'textarea',
'#title' => t('Message'),
'#rows' => 15,
'#required' => TRUE,
);
$form['submit'] = array('#type' => 'submit',
'#value' => t('Send e-mail'),
);
return $form;
}

function contact_mail_location_submit($form, &$form_state) {

global $language;

// Send the e-mail in the requested user language.
drupal_mail('contact', 'user_mail', $form_state['values']['recipient'], user_preferred_language($account), $form_state['values']['message'], $form_state['values']['from_email']);

flood_register_event('contact');
watchdog('mail', '%name-from sent %name-to an e-mail.', array('%name-from' => $user->name, '%name-to' => $account->name));
drupal_set_message(t('The message has been sent.'));

// Back to the requested users profile page.
$form_state['redirect'] = "user/$account->uid";
}

I then customized the view to not show the fields, and called the custom function and passed along the arguments. It seems work pretty well for what I need it for. It may not be the most elegant solution but it works well enough.

tryitonce’s picture

Thanks for reporting back and for giving the details of your solution.

This type of feedback makes this thread so much more valuable for anyone stumbling across it in their search for a solution.

Thanks and good luck ....