passing CCK email or node data to a webform
exobuzz - June 18, 2009 - 17:42
| Project: | Webform |
| Version: | 6.x-2.7 |
| Component: | Code |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
I have bumped into a variety of posts with this problem. Seems to be it is a basic requirement that you can pass the destination address from a node in drupal to the webform system, but I can't see how. Passing the email in the URL is not an option, as you are just asking for your form to be abused then by spammers. I would like to pass through a node ID, and then write a small piece of php so that webform can get the email address from this node. I know how to make the php to get the datam, but how can I integrate this with webform?
Unless I have missed something?

#1
I found the validation php box and have got as far as the code below. So i take the value of a hidden field and load the node to get the email address out. I now want to stick this address back into the form data so it can be submitted to that address but I have no idea which part of $form or $form_state to modify as the value appears multiple times. is it possible to change the form in the validation stage?
<?php$nid = $form['submitted']['centre']['#value'];
if ( $nid == '' ) {
form_set_error('centre','No such centre');
} else {
$node = node_load($nid);
if ( is_array($node->field_email) ) {
// where can i change the value of this form field? it exists in $form_state as well as $form and in multiple places!
//$form['submitted']['centre']['#value'] = $node->field_email[0]['email'];
} else {
form_set_error('centre','No valid contact email or no such centre');
}
}
?>
Has anyone else done something similar. I find no documentation on how to do this. The code above is worked out from lots of debug output etc.
#2
I'm getting closer. I can change the value of the form now, but the form still goes to "the id" that was set before
validation code
<?php$nid = $form_state['values']['submitted_tree']['centre'];
if ( $nid == '' ) {
form_set_error('centre','No such centre');
} else {
$mynode = node_load($nid);
if ( ! is_array($mynode->field_email) ) {
form_set_error('centre','No valid contact email or no such centre');
}
}
?>
processing code
<?php// set the field to the actual email address for the centre
$nid = $form_state['values']['submitted_tree']['centre'];
$mynode = node_load($nid);
$form_state['values']['submitted_tree']['centre'] = $mynode->field_email[0]['email'];
?>
any help would be most appreciated
#3
SOLVED!
for the process code i use the following
<?php// get the email for the node
$nid = $form_state['values']['submitted_tree']['centre'];
$mynode = node_load($nid);
// set the destination for the form to the email
$node->webform['email'] = $mynode->field_email[0]['email'];
?>
hopefully others will find this useful too.
#4
Automatically closed -- issue fixed for 2 weeks with no activity.
#5
exobuzz... absolutely brilliant! Thanks a ton!
#6
This is exactly the logic I need ... still doesn't seem to work for me.
It seems like I can't modify that field : $node->webform['email']
In my case, the mail is deduced this way : node url (HTTP_REFERER) -> node id -> author id -> author email
Actually, my validation block is empty. Could this be the reason ?
Thanks in advance for any advice.
EDIT : well I used a hidden field to catch the node id in $_GET (%get[nid]) instead of using the HTTP_REFERER and it works just fine! Thank you for the trick!