I am using Webform in conjunction with Webform Block, using the form as a block and displaying the block in the content bottom region of nodes of a specific content type. The content of the nodes are travel arrangements and the form should allow the user to send a booking request with the form.

What I would like to achieve is that the title of the node (the destination) should be automatically loaded into a field of the form ("Betreff:" in the screenshot). So if the title of the node is "Seefestspiele Mörbisch", this title should be loaded into the field "Betreff:" and submitted by email.

I have tried to work with %get[title] as a standard value for the form but it did not work.

Any suggestions?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

criscom’s picture

Title: Automatically Fill A Form Field With the Node Title » It's a pain in the ass - for me too - but

maybe you could help me out with a comment or two. I am no PHP expert and struggling...

criscom’s picture

Title: It's a pain in the ass - for me too - but » Automatically Fill A Form Field With the Node Title
criscom’s picture

nobody there with just a faint hint or something????

quicksketch’s picture

This currently isn't possible without custom coding (as far as I know). The only way I can think of doing it is using the additional processing code to check the current URL, loading the node, then setting the value of a field. However I don't provide support on how to write custom code in the Webform issue queue. See http://drupal.org/handbook/modules/webform/submission-code

vernond’s picture

Try something like this in the "additional validation" processing block:

<?php
$form_values['submitted_tree']['your_field_name'] = $node->title;
?>
criscom’s picture

Thanks quicksketch and vernond for your help. I'll try out your suggestions and report back!

loophole080’s picture

try the prepopulate module http://drupal.org/node/228167 - i've found it very handy, though i haven't used it with webform - but it's supposed to work see http://drupal.org/node/587306

pontus_nilsson’s picture

I solved it by using a hook_form_alter() in my custom module. It looks like this:

/**
* Implementation of hook_form_alter()
*/
function YOURMODULE_form_alter(&$form, &$form_state, $form_id) {

switch ($form_id) {
    case 'webform_client_form_YOURWEBFORMID':
      if(arg(0)=='node' && is_numeric(arg(1))) {
      $node = node_load(arg(1));
      // Add the node title to the webform field      
      $form['submitted']['YOURFIELD']['#default_value'] = $node->title;
      }
      return $form;
    break;
  }
}

If additional processing does it, I would go for that instead.

You can find YOURWEBFORMID by doing a dpm($form_id); before switch ($form_id) { if you have the Devel module installed. Or just use print_r($form_id);

In my case I had a hidden field with the node title inserted.

quicksketch’s picture

Status: Active » Closed (fixed)
Sinan Erdem’s picture

subscribing...