Drupal 7: Node fields in webform

I have a webform that appears in a block on content type 'job'. I am trying to get two fields from the node into the webform submission. I have this custom module:

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'];  
    }  }
}  

However, I'm getting this error:

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

Any thoughts on how to get the email field in the webform submission?

Answers


I think this error because of the following line:

// ERROR HERE...
$form['submitted']['email']['#value'] = $node->field_email[0]['value'];

This should go like this:

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

OR:

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

Hope this helps... Muhammad.


A little more tinkering around and I figured it out (thanks to Muhammad Reda for pointing me in the right direction).

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

I am new to Devel, but looking at the load, then just putting each level in brackets seemed to work.


Need Your Help

MQLight Node.js clients stops receiving messages after idle time. AMQP/MQ Light on MQ 8.0.0.3

node.js ibm-mq amqp

I am having an issue with using the Node.js client with an IBM MQ 8.0.0.3 server.

java.io.file help selecting multiple files from folder and listing hash values

java file hash

The first program should take two inputs as arguments: directory1 and directory2. the program should compute a hash value (using HMAC) for each file in the folder directory1 and store that hash value...