I want to calculate data which are submitted by Webform with figures that are already set in nodes.
As an Example let's assume I have put up a content-type 'cars' which contain the fuel consumption of a specified car if driving in the city and on a highway. So I have one node for each car.
It should be possible to put in the driven distance in a city and on a highway into a Webform and by submitting the data, one should get redirected to a view which shows the results like fuel consumption total, in the city and on the highway for each car.
I guess the calculation itself could be done by a 'computed field' in the node-type 'cars'. And the comparison can be shown with a view. But the point I couldn't solve yet is how do I get the submitted data to the nodes?
I tried to redirect from Webform to a node with a computed field in which I used:
$form_values['submitted_tree']['form_input']
and
$_POST['submited']['form_input']
but that doesn't fly.
What code do I need to use to get the submitted data in the redirected node(s)?
Comments
I suggest you try storing
I suggest you try storing the data ("distance") in $_SESSION e.g. something like $_SESSION['distance'] = $form_values['submitted']['distance']. You can then pick this up in the nodes (and then unset it if you want).
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Thanks a lot for your tip.
Thanks a lot for your tip. But somehow I couldn't figure out how to apply it.
I used the following code in the 'Additional Processing' field in webform:
And I put the following code in the redirected node:
But nothing is showing up there.
Actually I'm wondering if it is really neccessary to store the form data in $_SESSION. Because if I activate 'full debug' in the webform settings, all the fom variables show up in the redirected node in this way:
* $form_values are:
Array
(
[submitted] => Array
(
[2] => 100
[1] => 200
)
[details] => Array
(
[email_subject] => none
[email_from_name] => none
[email_from_address] => mail@email.cc
[nid] => 1
[sid] => 87
[is_new] => 1
)
[op] => Submit
[submit] => Submit
[form_token] => 08eb9c2656df60ad7905a656ff218b5a
[form_id] => webform_client_form_1
[submitted_tree] => Array
(
[input_1] => 100
[input_2] => 200
)
)
* $_SERVER is:
Array
(
[REDIRECT_STATUS] => 200
[HTTP_HOST] => localhost
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8.1.16) Gecko/20080702 Firefox/2.0.0.16
[HTTP_ACCEPT] => text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
[HTTP_ACCEPT_LANGUAGE] => de-de,de;q=0.8,en-us;q=0.5,en;q=0.3
[HTTP_ACCEPT_ENCODING] => gzip,deflate
[HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7
[HTTP_KEEP_ALIVE] => 300
[HTTP_CONNECTION] => keep-alive
[HTTP_REFERER] => http://localhost/drupal1/node/1
[HTTP_COOKIE] => SESSe68a5598f27bdd46df5887bf895e93fb=a82ee1a295030404a14d3f5195133f44
[CONTENT_TYPE] => multipart/form-data; boundary=---------------------------4016447115889
[CONTENT_LENGTH] => 976
[PATH] => C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;D:\PROGRA~1\DISKEE~1\DISKEE~1\
[SystemRoot] => C:\WINNT
[COMSPEC] => C:\WINNT\system32\cmd.exe
[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
[WINDIR] => C:\WINNT
[SERVER_SIGNATURE] =>
Apache/2.2.4 (Win32) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8d mod_autoindex_color PHP/5.2.1 Server at localhost Port 80
[SERVER_SOFTWARE] => Apache/2.2.4 (Win32) DAV/2 mod_ssl/2.2.4 OpenSSL/0.9.8d mod_autoindex_color PHP/5.2.1
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 0.0.0.0
[DOCUMENT_ROOT] => D:/Apache/htdocs
[SERVER_ADMIN] => admin@localhost
[SCRIPT_FILENAME] => D:/Apache/htdocs/drupal1/index.php
[REMOTE_PORT] => 0
[REDIRECT_QUERY_STRING] => q=node/1
[REDIRECT_URL] => /drupal1/node/1
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
[QUERY_STRING] => q=node/1
[REQUEST_URI] => /drupal1/node/1
[SCRIPT_NAME] => /drupal1/index.php
[PHP_SELF] => /drupal1/index.php
[REQUEST_TIME] => 1218877018
[argv] => Array
(
[0] => q=node/1
)
[argc] => 1
)
* $_POST is:
Array
(
[submitted] => Array
(
[input_1] => 100
[input_2] => 200
)
[details] => Array
(
[email_subject] => none
[email_from_name] => none
[email_from_address] => mail@email.cc
)
[form_token] => 08eb9c2656df60ad7905a656ff218b5a
[form_id] => webform_client_form_1
[op] => Submit
)
So for it looks like the form data are turned over to the node anyway. As well the session ID gets added to the URL: http://localhost/drupal1/node/7?sid=87
Webform has come on a bit
Webform has come on a bit since I last used it in anger so I'm not familiar with the debug output thing but I suspect that it does it by storing all that data in the session. (BTW sid is submission id.)
However the debug output shows you how to refer to your form field. The 'submitted' array has 2 elements with keys 2 and 1. Looks like 'submitted_tree' contains the inputs referenced by field name, so try using that instead of 'submitted'.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Thanks Giles. I see what you
Thanks Giles. I see what you mean. However, I tried as well code like:
or
I tried also to use those variables in computed fields in the referred node - all without the wanted results.
I thought as well that it should be quite easy to use the variables shown in the debug output for the wanted calculations or for displaying the data but it looks there is some basic component or concept missing here...
Actually I am trying since days to figure this out. I'm not a PHP coder and so I tried all thinkable ways that could be possible. :-/
Did you try your first
Did you try your first example in the Advanced -> additional processing box on the webform node? (Actually,
drupal_set_message($form_values['submitted_tree']['input_1']);might work better there.) Also trydrupal_set_message(print_r($form_values, TRUE));in the same place.If so then try storing it in the session and picking it up on the next page.
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk
Works now!
After reviewing the whole thing I found that your first tip was actually working, I just used 'submitted' instead of 'submitted_tree'. Of course this couldn't work that way!
So here the summary:
1. Put into 'Confirmation message or redirect URL' -field the node-id to redirect to in this way: internal:node/2
2. The 'Additional Processing'-field gets the following code:
3. In the redirected node you can now display the submitted value by using this code:
4. Or you can as well create a computed field in the redirected node which uses the submitted value for calculations:
Giles, thanks a lot for your useful advice!
:)
gpk
----
www.alexoria.co.uk
gpk
----
www.alexoria.co.uk