3

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?

1
  • Which line is line 35 ?! Commented Apr 26, 2012 at 8:27

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That's what I thought, but I still get this error: Notice: Undefined index: value in webform_nodevalues_form_alter() (line 35 of /drup/sites/all/modules/webform_nodevalues/webform_nodevalues.module).
1

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.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.