I currently have 2 webforms displayed on a page - these are inserted dynamically from a node.tpl.php file.

However, I also have a cck field on the current node for an email address - I would like to be able to pass this email value directly to the "Email To" field of the webform.

This would create a new email recipient depending on which node you were viewing. For example:

The "About Us" page contained the field "email: [email protected]" - therefore the webform loaded in the sidebar would be sent to this address.

The "Location" page contains the field "email: [email protected]" - now this would be the email address that receives any submissions from that page.

The idea is to have 1 webform and dynamically change the email its sent to based on a cck field. Is this possible at all?

Thanks, Garry.

2 Answers 2

  1. In your webform add an "email field" for the recipient (say email_recipient).

  2. Go to node/123/webform/emails to set the recipient to be your previously created field.

  3. Create a hook_form_alter to put the email address you your webform field.

    function CUSTOM_form_alter(&$form, &$form_state, $form_id) {
      //you need to set up a CUSTOM module to store this.
      //use devel with dsm($form); to figure the name of each field
      if ($form['#id'] == 'webform-client-form-123') {
        //load the node from the url
        if (arg(0) == 'node' && is_numeric(arg(1))) {
          $node_email = node_load(arg(1));
          //set your webform field to your email
               = $node_email->field_email_recipient[0]['value'];

Add some CSS to hide the field, and it should work, code untested but I'm pretty confident about the steps, also have a look at Working with Default Values.

  • Thanks for the response, I have setup my custom module and added the recipient email field to my form. However, I am receiving an error with your code "Fatal error: Can't use function return value in write context in..." I also don't see where my CCK email field is being inserted into the webform. Do you have anymore instructions? Cheers, Garry.
    – Garry
    Commented Jun 16, 2011 at 9:12
  • @Garry which line cause the error ? Do you see your recipient field being populated with your CCK ?
    – tostinni
    Commented Jun 16, 2011 at 14:04

I know this is old, but in case anyone else comes up with this problem, the problem is this line:

if (arg(0) = 'node' && is_numeric(arg(1))) {

should be

    if (arg(0) == 'node' && is_numeric(arg(1))) {
  • Your post not attempt to answer this question, explain in brief!!
    – Bala
    Commented Sep 26, 2013 at 7:33
  • Yep I fixed it, thanks for the bug report ;) but it should be a comment on my answer as yours isn't a proper answer.
    – tostinni
    Commented Aug 29, 2014 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.