开发者

Custom Contact Form on a Drupal CCK Node

What would be the best way to construct a contact form in Drupal 6 for each node of a particular type? I have some CCK nodes of type "profile" which have email address as a field. I want to have a view for each node with a contact form that us开发者_如何学JAVAers can fill out and send with their own email address as a return address (so that further contact is being done offsite).

Basically I just want that initial email contact to be done through my site, and when the recipient replies it just goes to the address that the sender entered when they filled out the contact form.

You might be asking yourself why I don't use the personal contact form that comes baked into Drupal. The issue is that the way my institution deploys their Drupal instances to use the local Kerberos logins, the user accounts it creates in Drupal do not have email addresses. They just get a basic skeleton account with username. I don't really want to force users to go through another hoop of editing their user account info, because they most likely just won't do it.


There is nothing to do particularly with node itself, all you need for this - is form with fields (from, to, subject, message) and custom submit handler for this form. you can implement all this in custom module using forms API to create form and write custom submit for it. And in this submit you need to send email via drupal_mail() - take a look at this, it is provides examples as well. That topic can help you with forms.

Then, if you need to place this form within a node, you can do the following: via hook_nodeapi, on "view" operation, add form you've created before, you can check for particular node_type and use existing field values (you mentioned cck field with email) to pre-fill form. So that every time user views node, he sees this form.

as logical continue of your task, I suggest it makes sense to take a look at menu system and create local task (tab) for the node, where you'll display email form.

In general, that's all. There are of course other ways of implementing this, however I think this one is the easiest for understanding.

Regards, Slava

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜