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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With