I am creating an RFP section on my site. Users can post a job (the content type) and in that node they add in their email address.

I created a webform "Submit a quote" ... I was hoping I could attach that to every "Job" content type. Then, it would get emailed to the email field from the node. It would also include the node title, author, and date.

Is there a way to do this?

CommentFileSizeAuthor
#23 Error_mail.jpg159.45 KBmariusm
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

MrPeanut’s picture

I thought I searched, but it looks like I didn't do a very good job. Here is a similar issue: #1397458: Default webform attached to new content.

quicksketch’s picture

Great, thanks for searching. I think I've already given my best answer in that other issue. webform_default_fields.module is probably the best (or at least easiest) way to go.

MrPeanut’s picture

I couldn't quite figure out webform_default_fields, but I did find this post by you but had trouble with that as well. (Here's my comment in that thread.)

This is the error that I get:

Error messageNotice: Undefined offset: 0 in webform_nodevalues_form_alter() (line 35 of /drup/sites/all/modules/webform_nodevalues/webform_nodevalues.module).

MrPeanut’s picture

@quicksketch Is this code not valid for Drupal 7?

function webform_nodevalues_form_alter(&$form, $form_state, $form_id) {
  // 1. Webform ID
  if ($form_id == 'webform_client_form_237') {
    if ($node = menu_get_object()) {
      // 2. Webform field for the node title
	  $form['submitted']['title']['#value'] = $node->title;
	  // 3. Webform field for a CCK field
      $form['submitted']['email']['#value'] = $node->field_email[0]['value'];
	}
  }
}

I'm trying to get the data from field_email (my node field) into the email field of my webform.

MrPeanut’s picture

Status: Active » Closed (works as designed)

I am notorious for searching hours upon hours, finally asking for help, then figuring it out.

$form['submitted']['email']['#value'] = $node->field_email['und'][0]['email'];

prezaeis’s picture

hey man
im trying to achieve the exact same thing, but im not having any luck, ive put the code in a new module and installed it but its not working

can you give me a quick run down of how u did it? maybe upload the module as well? id really appreciate it

MrPeanut’s picture

I downloaded the module from this comment, changed the info to be a Drupal 7 module, then just updated the webform ID and CCK field using the code from my comment (#5).

Add the webform block to your pages, check 'Show all webform pages in block' on the config, and you should be set.

To test it, you can try just the title (comment out the CCK field) and set a default email address. See if it captures the title and emails.

yatil’s picture

Did basically the same thing and it didn’t work out:

My module says:

/**
 * Implements hook_form_alter to provide node values to Webform.
 */
function webform_nodevalues_form_alter(&$form, $form_state, $form_id) {
  // 1. Webform ID
  if ($form_id == 'webform_client_form_166') {
    if ($node = menu_get_object()) {
      // dpm($node->field_e_mail_adresse['und'][0]['value']);
      // dpm($form);
      // 2. Webform field for the node title
      $form['submitted']['nodetitle']['#value'] = $node->title;
      // 3. Webform field for a CCK field
      $form['submitted']['e_mail_to']['#value'] = $node->field_e_mail_adresse['und'][0]['value'];
      // dpm($form);
    }
  }
}

and there are even the right values in the HTML hidden form elements. But when the form gets actually sent, both values, the e_mail_to and the nodetitle are empty. I can see the sent forms on the results pane, but there is no email sent. How can that be?

MrPeanut’s picture

This is how I troubleshooted it. Set up an email in the webform (node/#/webform/emails) to go to your email address only. Submit the form. Did the two fields have values? If not, your module code is incorrect.

For me, it was $node->field_e_mail_adresse['und'][0]['value']; needed to be $node->field_e_mail_adresse['und'][0]['email']; (email instead of value).

incaic’s picture

Here's another solution. The following module code exposes the current top level page node through tokens, which I called "page-node". It's similar to the code in the Token module. I called the module page_node_token. I had to also create a hook_field_display_alter() function to take care of fields being displayed without a default_token_formatter. This is needed if you are using the email module.

After installing this module you will see a "Page Node" family of dynamic tokens when you are editing a form component. This allowed me to use my top level email field by entering [page-node:field_email].

Drupal 7.15
Webform 7.x-4.0-alpha4
Token 7.x-1.2

page_node_token.install
Increase module weight so that page_node_token_field_display_alter() is executed after token module

/**
 * @file
 * Install, update, and uninstall functions for page_node.
 *
 * @ingroup page_node
 */

/**
 * Implements hook_install()
 */
function page_node_install() {
    db_update('system')
    ->fields(array('weight' => 1))
    ->condition('type', 'module')
    ->condition('name', 'page_node')
    ->execute();
}

page_node_token.info

name = Page node tokens
description = provide top level page-node tokens
package = Other
core = 7.x
dependencies[] = token

page_node_token.module

/**
 * Implements hook_token_info().
 *
 * Provide information about current page top level page node
 *
 * @see httx://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_token_info/7
 * @see httx://api.lullabot.com/token_example_token_info/7
 * @return array
 *   An associative array of available tokens and token types.
 */
function page_node_token_token_info() {
  $info['types']['page-node'] = array(
    'name' => t('Page Node'),
    'description' => t('Tokens related to current top level page node'),
  );
  return $info;
}

/**
 * Implements hook_token_info_alter().
 *
 * Use hook_token_info_alter() rather than hook_token_info() as other
 * modules may already have defined some field tokens.
 */
function page_node_token_token_info_alter(&$info) {
  $fields = _token_field_info();

  // Attach field tokens to their respecitve entity tokens.
  foreach ($fields as $field_name => $field) {
    foreach (array_keys($field['bundles']) as $token_type) {
      // Only add node fields to page-node
      if ($token_type == 'node') {
        $type = 'page-node';
        $info['tokens'][$type][$field_name] = array(
          // label and description have already been sanitized by _token_field_info().
          'name' => $field['label'],
          'description' => $field['description'],
          'module' => 'page_node_token',
        );
      }
    }
  }
}

/**
 * Implements hook_tokens().
 *
 * Provide replacement values for placeholder tokens.
 *
 * @see httx://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_tokens/7
 * @see httx://api.lullabot.com/token_example_tokens/7
 * @param string $type
 *   The machine-readable name of the type (group) of token being replaced, such
 *   as 'node', 'user', or another type defined by a hook_token_info()
 *   implementation.
 * @param array $tokens
 *   An array of tokens to be replaced. The keys are the machine-readable token
 *   names, and the values are the raw [type:token] strings that appeared in the
 *   original text.
 * @param array $data (optional)
 *   An associative array of data objects to be used when generating replacement
 *   values, as supplied in the $data parameter to token_replace().
 * @param array $options (optional)
 *   An associative array of options for token replacement; see token_replace()
 *   for possible values.
 * @return array
 *   An associative array of replacement values, keyed by the raw [type:token]
 *   strings from the original text.
 */
function page_node_token_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  $sanitize = !empty($options['sanitize']);
  $langcode = isset($options['language']) ? $options['language']->language : NULL;

  // Page-Node tokens
  if ($type == 'page-node') {
    // page node type
    $entity_type = 'node';
    $entity = clone menu_get_object();
    unset($entity->_field_view_prepared);

    list(, , $bundle) = entity_extract_ids($entity_type, $entity);
    $fields = field_info_instances($entity_type, $bundle);

    foreach (array_keys($fields) as $field_name) {
      // Do not continue if the field is empty.
      if (empty($entity->{$field_name})) {
        continue;
      }

      // Replace the [page-node:field-name] token only if token module added this token.
      if (isset($tokens[$field_name]) && _token_module($entity_type, $field_name) == 'token') {
        $original = $tokens[$field_name];
        $field_output = field_view_field($entity_type, $entity, $field_name, 'token', $langcode);
        $field_output['#token_options'] = $options;
        $field_output['#pre_render'][] = 'token_pre_render_field_token';
        $replacements[$original] = drupal_render($field_output);
      }
    }

    // Remove the cloned object from memory.
    unset($entity);
  }

  return $replacements;
}

/**
 * Implements hook_field_display_alter().
 *
 * Fix for fields that don't have 'default_token_formatter' set in hook_field_info()
 */
function page_node_token_field_display_alter(&$display, $context) {
  if ($context['view_mode'] == 'token') {
    $view_mode_settings = field_view_mode_settings($context['instance']['entity_type'], $context['instance']['bundle']);
    if (empty($view_mode_settings[$context['view_mode']]['custom_settings'])) {
      $field_type_info = field_info_field_types($context['field']['type']);
      if (empty($field_type_info['default_token_formatter'])) {
        $disp = '';
        switch ($field_type_info['module']) {
          case 'email':
            $disp = 'email_plain';
            break;
        }
        if (!empty($disp)) {
          $display['type'] = $disp;
          $formatter_info = field_info_formatter_types($display['type']);
          $display['settings'] = isset($formatter_info['settings']) ? $formatter_info['settings'] : array();
          $display['settings']['label'] = 'hidden';
          $display['module'] = $formatter_info['module'];
        }
      }
    }
  }
}
jainparidhi’s picture

Hello incaic,

Thank you for modifying the module code for Drupal 7. However, I tried using your code and it did not work for me. I removed the php tags in your .info file as it was giving an error. The Page-node dynamic tokens do not show up in form component settings. I do not nee email field, rather another CCK field to populate a webform hidden field. Please let me know if I am doing something wrong...

Thank you so much for the input!

PJ

incaic’s picture

I changed the php tags to code tags for the .info file in #10 above. This should work for Drupal7 nodes with fields you created. It should show you all the available fields. If you see some, but not the one you want, then you probably used a contrib module field type (i.e. email) that doesn't have a 'default_token_formatter' set in its hook_field_info(). If so, you would need to add a new case for the switch statement in page_node_token_field_display_alter().

hockey2112’s picture

incaic,

I installed your custom module (Drupal 7), but I am not seeing any additional tokens when I edit my hidden webform item. I am trying to use a single application webform for any number of available job positions, and I want the submission to include the name of the job being applied for. The Webform is placed as a block on each job's page... can your module be used to somehow capture the job name from that page and include it in the submission?

incaic’s picture

hockey2112,

Your setup sounds similar to mine. How do you build out the job's page? If the job is a node type then I would suggest using Display Suite to create the page. Then, when viewing the job's page the job node would be page_node in the custom module.

Hope that helps.

hockey2112’s picture

incaic,

I am using Display Suite to manage the display of my job content type's fields. In the Manage Fields tab for job content, I have Body and my Webform.

In the webform, I created a hidden field with "%page_node" as the value... it simply returns that text ("%page_node") in the form submission. If I use %title, it gives me the title of the webform itself (not the title of the job's page, which is what I need.

On the webform's hidden field page, these are the tokens it lists:

Basic tokens

%username - The name of the user if logged in. Blank for anonymous users.
%useremail - The e-mail address of the user if logged in. Blank for anonymous users.
%ip_address - The IP address of the user.
%site - The name of the site (i.e. Deep River Snacks)
%date - The current date, formatted according to the site settings.

Node tokens

%nid - The node ID.
%title - The node title.

Special tokens

%profile[key] - Any user profile field or value, such as %profile[name] or %profile[profile_first_name]
%get[key] - Tokens may be populated from the URL by creating URLs of the form http://example.com/my-form?foo=bar. Using the token %get[foo] would print "bar".
%post[key] - Tokens may also be populated from POST values that are submitted by forms.

I'm sure I am missing something somewhere. Hopefully something above sticks out to you. ;)

Thanks!

hockey2112’s picture

incaic,

It looks like my issue is the fact that I am using Webform 3.x. Is it possible at all to use the custom module with 3.x, or is 4.x required?

incaic’s picture

Webform description says, "If you want Drupal 7 style tokens or use conditionals, you should install the 4.x branch."
If you are able to, upgrade and try it out and let us know.

hockey2112’s picture

I upgraded to Webform 4.x, and the tokens seem to be working perfectly. Thanks!

nikkubhai’s picture

Dear incaic,
Thank you so much. I used the your code and it worked well except one small problem. The field value now shows
<a href="mailto:test@gmail.com">test@gmail.com</a>

while I want it just to be test@gmail.com

What should I do?

incaic’s picture

@nikkubhai

It does that because the default email display format is a mailto link. The code in page_node_token_field_display_alter() takes care of that, but don't forget to have it executed after the token module. I edited my post above and added the page_node_token.install file that increases the module weight to 1 which is greater than token module's default weight of 0.

Follow the following steps:

1) disable the page_node_token custom module
2) uninstall the page_node_token custom module
3) create the page_node_token.install file with the code shown above
4) enable the page_node_token module

nikkubhai’s picture

@incaic : Sorry, but I am still facing that problem. :(

incaic’s picture

@nikkubhai

1) Verify the module versions I stated above (and email 7.x-1.2) are the ones you are using
2) Double check that the weight for page_node_token is set to 1 in the system table in the database. (If not, manually change it to 1 and see if that fixes it.)
3) If #2 doesn't fix it, then put some devel print messages in at email module function email_field_formatter_view() and find out which case is being executed: email_default, email_plain, etc.

mariusm’s picture

FileSize
159.45 KB

Hello incaic,

I have

Drupal 7.16
Webform 7.x-4.0-alpha6
Token 7.x-1.2
Email 7.x-1.2

When I try to set

"E-mail to address " with token [page-node:field_email]

I received the error shown in the attachment :

( ! ) Fatal error: __clone method called on non-object in D:\wamp\www\testdr\sites\all\modules\page_node\page_node_token.module on line 80

Thanks,
Marius

mariusm’s picture

I solved following the instructions http://drupal.org/node/1760332

Thanks

mariusm’s picture

@nikkubhai

go to

admin/structure/types/manage/YourContent/display/token

select email format "Email Plain text"

Marius

incaic’s picture

@mariusm, @nikkubhai

Just a quick clarification.

The instructions you point out are useful when one is sending emails to an email address set on the webform. The custom module above that creates page-node tokens are for when the email is set in the top level page node not in the webform itself.

sircosta’s picture

@mariusm, finally, worked 'page-node' custom module to you? using http://drupal.org/node/1760332 instructions?

@incaic Thanks for your your custom module, nevertheless, an error appears using it:

'Fatal error (...) sites\all\modules\page_node\page_node_token.module on line 80'

Drupal 7.16
Webform 7.x-4.0-alpha6
Token 7.x-1.2
Email 7.x-1.2

As you say in your last comment, it is better not to use this custom module using http://drupal.org/node/1760332 instructions?

incaic’s picture

@sircosta

Provide more info on the error and I'll take a look at it.

sircosta’s picture

Hi @incaic.

Just an error appears when I try to add new content (node/add/content-type) and it is:

Fatal error: __clone method called on non-object in /home/example.com/sites/all/modules/page-node/page_node_token.module on line 80

I follow the http://drupal.org/node/1760332 instructions:

1.Create the field
2.Hide the field
3.Set the display mode to plain text ["Email plain text" in token content-type view mode]
4.-Add a new Hidden component
4.1 Label, Field Key
4.2 Default value
This is the field where you add the token to pull information from the container node. These follow the pattern:

[node:field_YOUR_FIELD_NAME] (Token module) + Here I use Page Node module and I've use [page-node:field_email] token.

4.3.- Display > Hidden Type

Using:

Drupal 7.17
Webform 7.x-4.0-alpha6
Token 7.x-1.4
Email 7.x-1.2

If you need more details, please tell me.

Thanks again.

Alan D.’s picture

The custom code should check the menu object

  $node = menu_get_object();
  // Page-Node tokens
  if ($node || $type == 'page-node') {
    // page node type
    $entity_type = 'node';
    $entity = clone $node;
    unset($entity->_field_view_prepared);

incaic’s picture

Alan is correct.
Need to check whether the current page is the full page view of the passed-in node.

function page_node_token_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  $sanitize = !empty($options['sanitize']);
  $langcode = isset($options['language']) ? $options['language']->language : NULL;

  // Page-Node tokens
  if ($type == 'page-node' && $node = menu_get_object()) {
    // page node type
    $entity_type = 'node';
    $entity = clone menu_get_object();
    unset($entity->_field_view_prepared);

    list(, , $bundle) = entity_extract_ids($entity_type, $entity);
    $fields = field_info_instances($entity_type, $bundle);

    foreach (array_keys($fields) as $field_name) {
      // Do not continue if the field is empty.
     if (empty($entity->{$field_name})) {
        continue;
      }

      // Replace the [page-node:field-name] token only if token module added this token.
      if (isset($tokens[$field_name]) && _token_module($entity_type, $field_name) == 'token') {
        $original = $tokens[$field_name];
        $field_output = field_view_field($entity_type, $entity, $field_name, 'token', $langcode);
        $field_output['#token_options'] = $options;
        $field_output['#pre_render'][] = 'token_pre_render_field_token';
        $replacements[$original] = drupal_render($field_output);
      }
    }

    // Remove the cloned object from memory.
    unset($entity);
  }

  return $replacements;
}
mariusm’s picture

Hello incaic,

Please add a token for node author email like [node:author:mail]

Thanks,
Marius

swfindlay’s picture

@incaic Thank you for this module.

I can see the Page Node tokens, however, when I use them in the Webform, they don't return any values. (I've set up an email which send the Field Tokens to me on submission of the Webform).

My setup:
- Webform as block.
- My_Content_Type as the Page
- various Fields - including text
- Webform 7.x.4.x

Is there something that I am missing / doing wrong?

Thanks

illuminatico’s picture

Version: 7.x-3.9 » 7.x-4.0-alpha6

I'm having the same issue as @swfindlay. I have successfully gotten this to work on another site, using the same method, but now I am running into the issue where the webform is not grabbing the value for the field i have selected from the page node tokens list. At first I thought it was because of my node--mycontenttype.tpl.php page, but after completely removing it, I still can't get the value to populate.

illuminatico’s picture

I got this working. I deleted the current form and recreated it and it worked. I have the form displaying in a block on the sidebar.

illuminatico’s picture

I think that selecting "display all webform pages in block" as well as selecting the specific content type to display the form on helped.

GiorgosK’s picture

one can also use http://drupal.org/project/token_custom module as I described here http://drupal.org/node/1849804 to get the node email and pass it to webform

swfindlay’s picture

Thanks @illuminatico I rebuilt the form and it now works.

Two other things I noticed when debugging:
- If the webform component is "Hidden" then under Display for that component select "Hidden Element" not "Secure Value"
- In the Tokens view for the nodetype (example.com/admin/structure/manage/[nodetype]/display/token) ensure the field is visible (i.e. not hidden), even if you don't actually want this field to be seen under the main display

Hope this helps anyone else trying to troubleshoot!

incaic’s picture

@swfindlay - glad it worked for you

But, not sure about your two comments:
- I am using a hidden email webform component whose value I get from [page-node:field_email] and the display hidden type I use is "Secure value".
- I don't have/use a token view mode (i.e ..../[nodetype]/display/token).

Terrodactyl’s picture

Thanks a lot incaic for your support.

Your module + http://drupal.org/node/1760332 got this working for me.

You made me so happy :)

jasom’s picture

Hi there,
token [node:author:mail] which suggested mariusm #32 is very welcome. How I can get it? It is possible to add it to you module incaic?

[node:author:mail] is a token for author of node where is webform block displayed.

bysv’s picture

Thank you incaic for the module in #10.

Is it possible to add a token with the author's email of the the node ([page-node:author:mail])?

I also would be interested in a token like this.

Thanks!!

incaic’s picture

Make these changes to get access to the page-node author token tree.

1) Replace page_node_token_info_alter() with this one:

/**
 * Implements hook_token_info_alter().
 *
 * Use hook_token_info_alter() rather than hook_token_info() as other
 * modules may already have defined some field tokens.
 */
function page_node_token_token_info_alter(&$info) {
  $type = 'page-node';
  $fields = _token_field_info();

  // Attach field tokens to their respecitve entity tokens.
  foreach ($fields as $field_name => $field) {
    foreach (array_keys($field['bundles']) as $token_type) {
      // Only add node fields to page-node
      if ($token_type == 'node') {
        $type = 'page-node';
        $info['tokens'][$type][$field_name] = array(
          // label and description have already been sanitized by _token_field_info().
          'name' => $field['label'],
          'description' => $field['description'],
          'module' => 'page_node_token',
        );
      }
    }
  }
  // Core node author token tree for page-node
  $info['tokens'][$type]['author'] = $info['tokens']['node']['author'];
}

2) Replace page_node_token_tokens() with this one:

/**
 * Implements hook_tokens().
 *
 * Provide replacement values for placeholder tokens.
 *
 * @see http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_tokens/7
 * @see http://api.lullabot.com/token_example_tokens/7
 * @param string $type
 *   The machine-readable name of the type (group) of token being replaced, such
 *   as 'node', 'user', or another type defined by a hook_token_info()
 *   implementation.
 * @param array $tokens
 *   An array of tokens to be replaced. The keys are the machine-readable token
 *   names, and the values are the raw [type:token] strings that appeared in the
 *   original text.
 * @param array $data (optional)
 *   An associative array of data objects to be used when generating replacement
 *   values, as supplied in the $data parameter to token_replace().
 * @param array $options (optional)
 *   An associative array of options for token replacement; see token_replace()
 *   for possible values.
 * @return array
 *   An associative array of replacement values, keyed by the raw [type:token]
 *   strings from the original text.
 *
 * NOTE: Very similar to token_tokens()
 */
function page_node_token_tokens($type, $tokens, array $data = array(), array $options = array()) {
  $replacements = array();
  $sanitize = !empty($options['sanitize']);
  $langcode = isset($options['language']) ? $options['language']->language : NULL;

  // Page-Node tokens
  if ($type == 'page-node' && $node = menu_get_object()) {
    // page node type
    $entity_type = 'node';
    $entity = clone $node;
    unset($entity->_field_view_prepared);

    list(, , $bundle) = entity_extract_ids($entity_type, $entity);
    $fields = field_info_instances($entity_type, $bundle);

    foreach (array_keys($fields) as $field_name) {
      // Do not continue if the field is empty.
      if (empty($entity->{$field_name})) {
        continue;
      }

      // Replace the [page-node:field-name] token only if token module added this token.
      if (isset($tokens[$field_name]) && _token_module($entity_type, $field_name) == 'token') {
        $original = $tokens[$field_name];
        $field_output = field_view_field($entity_type, $entity, $field_name, 'token', $langcode);
        $field_output['#token_options'] = $options;
        $field_output['#pre_render'][] = 'token_pre_render_field_token';
        $replacements[$original] = drupal_render($field_output);
      }
    }

    // Remove the cloned object from memory.
    unset($entity);

    // Replace author token tree
    if ($author_tokens = token_find_with_prefix($tokens, 'author')) {
      $author = user_load($node->uid);
      $replacements += token_generate('user', $author_tokens, array('user' => $author), $options);
    }
  }

  return $replacements;
}
bysv’s picture

Thanks incaic!

I made these changes in page_node_token_token_info_alter() and page_node_tokens() but now the page-node tokens do not show any value. Even values ​​[page-node: field_FIELD_NAME] now do not show any data.

I have done something wrong??

Thank you very much for your help!

incaic’s picture

Sorry, I made a typo. It should be page_node_token_tokens() NOT page_node_tokens() since the module name is page_node_token.

bysv’s picture

Perfect incaic!
Now it works.

Thank you very much. I'll be eternally grateful

astuteman247’s picture

@incaic - this is a great module and works perfectly for when a user are logged in. However, I can’t seem to figure out why the fields don’t render for Anonymous users? Have you experienced this also?

Set Up
Webform as Block.
7.x-4.x

incaic’s picture

@astuteman247

I am only using this module for anonymous users, so I can't reproduce the problem. If you do a little debugging either with Xdebug or print statements to narrow down the problem, I might be able to help.

hstreitzig’s picture

Guys, you made my day.

In my case i had a content-type for jobs, displayed in panels with further information from user-profile (profile2). In a collapsible panel-region should displayed a webform for job-seekers. This form-results should be send to an e-mail-adress that user saved in the content.

I tryed so much things and days, to get this e-mail-adress as recipient - this thread was my milestone! With the changes from #43 it works perfectly!

Thanks

webby7097’s picture

I'm using the code above with all of the mentioned updates and modifications, and I'm not able to get at the variable I need; it doesn't show up under Page Node. I'm hoping someone can help me figure out why, or suggest an alternative.

I have email addresses as a field on a taxonomy called department, and am trying to get those addresses to attach as the 'to' field in the webform email. I can see the [page-node:field_department] as a token and it works, but I can't see the email; it shows up under [node:field-department:field_contact_email], but as it's not actually part of the webform node, it doesn't populate.

PascalMortier’s picture

Thank you incaic ! #10 works for me !

olisb’s picture

Issue summary: View changes

superb, thanks incaic. The code from #10 which I updated with #43 worked perfectly without any errors
allowing me to send a webform to the author of the node on which the webform was placed (and an admin)
which is also going to help me work a solution for webform registration (which does not seem quite ready in D7)
Many thanks for sharing this
olisb

maxlife58’s picture

Hi incaic yor module work very well but i've a problem, my field it's an email field created with email module and the token display the html code as <href-my_email_field....
and i can't use it to send the webform email.

I also try to put the email _field display as plain text but it's the same!

Any help or solution?

Thanks

maxlife58’s picture

Solved with #22 thanks incaic

incaic’s picture

@fromfriends-de, @PascalMortier, @olisb, @maxlife58 - I'm glad you got the code working and found it useful!

@webby7097 - Hope you got it working after some debugging.

youlikeit’s picture

Hi Isac
Thanks for your module. It works great for me but when submitted ad form it disabled my admin menu bar.
Any idea how to fix it? Has anyone else this problem and fixed it already??

millionleaves’s picture

I combined the module in #10 with the replacement functions supplied in #43.

I also replaced the .info content with this - the module wasn't appearing in the module list with the code as supplied, even after removing the PHP tags:

name = "Page node token"
description = "provide top level page-node tokens"
package = Other
core = 7.x
dependencies[] = token

With that done, I did the following:

  1. Enabled the module
  2. Added an email field to my webform
  3. Set the default value of the email field to [page-node:field_email_address] where field_email_address is the machine name of the email field in the node that I want to use. I was able to choose it from the list of available tokens.
  4. Enabled the Token display in the node type with the email address, and set the display of the email address to Plain Text
  5. Added the block to the node page

This was sufficient to get the block displaying on the page, showing the email address for the node in the email field thereby demonstrating that the module worked. From there, I was able to hide the field so it wouldn't be displayed to the user, but could be used as to send an email destination after form submission.

EDIT: I found that the module I created as described here caused problems when running database updates due to the query in the .install file. I experimented with removing the .install file altogether. The module appeared to keep working, and the update error went away. In any case, the query didn't seem to have set the module weight in the system table as it's supposed to (should be 1, was still set to 0). This may the the reason some people can't get this code to work.

I'm inclined to remove the .install file altogether unless someone can suggest a fix to the query. If the module won't work for you, the Module Weight module will let you manually set the weight of the module through the GUI. It will show you the weights of all the modules in your site. If Token appears below this module on your site, then change the weight of this module so it appears below Token in the list.

criscom’s picture

The custom module in #10 didn't work for me as there were issues with page manager:

PHP Fatal error:  __clone method called on non-object in /var/www/mysite/sites/all/modules/custom/page_node_token/page_node_token.module on line 80

I had to uninstall the module and found a patch for the token module here: https://www.drupal.org/node/919760#comment-9973163

Applying that patch against the token module made node specific tokens available in my webform block: go to >> available token patterns > current page > the current node > [current-page:node:my_field]

jasom’s picture

Applying that patch against the token module made node specific tokens available in my webform block: go to >> available token patterns > current page > the current node > [current-page:node:my_field]

You can send webform emails to the email field from the current node using dynamic token [current-page:query:?], no special module is required anymore. This "odd" token can extract each field of the current node and insert it into the message, subject, e-mail to... For example token for the date the current node was posted will looks like:

[current-page:query:?] + [node:created] = [current-page:node:created]

I wrote a tutorial here.

Rob T’s picture

Thanks to MrPeanut for the direction provided in #5 and #7. I was finally able to get (parent) node information included when submitting a webform in a block.

christine1126’s picture

Thanks Jasom (#59), it works great!

Maurice M.’s picture

Probably not the nicest wat to do this but it works.

Add a random emailaddress to your webform. (Not sure if this step is required).

Add the following code to your template.php hook_form_alter function.

if ($form['#id'] === 'webform-client-form-39') { // Change form ID 
	$node 	= menu_get_object(); // Gets the current page node
	$wrapper 	= entity_metadata_wrapper('node', $node);

	if (isset($wrapper->field_email_address)) {
		$email 		= $wrapper->field_email_address->value();

		$form['#node']->webform['emails'][1]['email'] = $email; // Override the emailaddress in the webform
	}
}