It´s a restaurants website. There´s a view where the user sees a list of all the restaurants in the website. These restaurants are "nodes". Each restaurant has an email field defined with CCK email field.

1) The question is: i want the contact form on the bottom of each restaurant page to send to the value of the email field(not to the writer of the node).

2) There should be a contact form on the bottom of the view too, where each restaurant will have a check box. The restaurants with the marked checkboxes will receive the content of the contact form sent to their email field value.

This is what i want to do:
My view should be like this: http://www.pipa.com.br/conteudo/servicos/pesquisa_imoveis.asp?idi=2
My node should be like this: http://www.pipa.com.br/vendeseterreno/english/

How can i do that? Can anyone help?

I even installed "Contact form on a Node" module, but no use.

Comments

aburrows’s picture

Download webform and webform block module, and then place the form in the node as a block.

empipa’s picture

i´m not sure i understood... how do i add that to the node? And how can the form get the node email adress(each node is a client with it´s own email address) the messages sent throught the form on the bottom of the page should go to him.

Is webform the best way to do that.

webdesigncapetown’s picture

If so how? I am looking for the same solution.

ecksley’s picture

So far it looks like Webform has no means of pulling the CCK email value from out of the node and then using it.

It offers only two means of establishing a destination address. 1.) manually enter one while configuring the webform, or 2.) Make it dependent on a component value by using a Conditional e-mail recipients.

Two of the available components would seem to have potential... The first is the Markup component which allows PHP. Therefore it is possible to load the node data in the webform block and get the email address. However, it turn out this component is not among those that can be used to supply a conditional e-mail recipients. The Second option is the Hidden component. Which is particularly nice because it is hidden. (Why go through all this mess unless you are trying to protect people's email addresses from being harvested.) Anyway, this field doesn't seem to support PHP although it does seem to be an option for conditional e-mail recipients.

Then I discovered the following on the webform page:

After setting up a Webform node, you may find the need for some kind of unique processing, such as sending the request to another script or adjusting the recipients of the sent email. Webform allows this through two special PHP fields for Additional Validation and Processing.

But after more testing even this yielded no fruit. Under additional processing I was able to change value of my Hidden field to set a conditional e-mail recipient as follows:

$nid = arg(1);
$node = node_load($nid);
$email = $node->field_email[0]['email'];

$component_cid = 6;
$form_values['submitted'][$component_cid] = $email;

But it looks like processing only occurs after the email is sent. In my case the default Hidden field value was emailed to me. But the database reflected the CCK field value change. I should also say the code above seemed to mess up the success message.

Oh well. I feel like I was very close here. Any ideas before I write an old fashioned email form? I wish I could find out what additional processing options exist?

ecksley’s picture

I got it to work after finding this page: http://drupal.org/node/323666 and experimenting for a while.

Basically, I disabled the standard recipient email entirely and inserted the PHP below in the Webform advanced settings>Additional Processing field.

<?php
$nid = arg(1);
//Just do an old fashion Sql Query to get the node's email address rather than a node load to prevent the previously mentioned success message problem it was causing
$sql = "SELECT field_email_email  FROM {content_type_job} WHERE nid = '$nid'";
$result = db_query(db_rewrite_sql($sql));
$email = db_fetch_object($result);
$email = $email->field_email_email;

// fetch data submitted via webform for later use in the body of the email.  The Numbers below can be found by rolling over the edit links when administering the components.  Look at the URLs and you'll see the related number
$params['first_name'] = $form_values['submitted'][4];
$params['last_name'] = $form_values['submitted'][5];
$params['email'] = $form_values['submitted'][3];
$params['message'] = $form_values['submitted'][2];

$to = $email;
// set sender
$from = "donotreply@mydomain.com";
// install devel module and uncomment next line to see entire data structure in a nifty little DHTML widget
// dpm($form);

// drupal message on confirmation page
drupal_set_message('Form has been sent');

// send the confirmation mail
drupal_mail('confirmation_reservation', 'confirmation_reservation_mail', $to, language_default(), $params, $from);

// construct email

function confirmation_reservation_mail($key, &$message, $params) {
  $message['subject'] = "Subject";
  $message['body'] = "An email has been submitted by the following user" . "
Name:". $params['first_name'] . " " . $params['last_name'] . "
Email:" . $params['email'] . "
Message:" . $params['message'] . "

Kindest regards,
Website
";
    }
?>