Closed (fixed)
Project:
Webform
Version:
5.x-2.x-dev
Component:
Miscellaneous
Priority:
Normal
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
11 Mar 2008 at 20:00 UTC
Updated:
7 Jun 2008 at 21:04 UTC
Is it possible, maybe with additional validation/processing, to perform some simple calculations on data being input into a webform?
I've got some forms where I'd like to have some of the fields be added up when submitting the form. And have the total amount be displayed in the submission email and stored in the database. I've tried to add some javascript I've used on other html forms to the webforms without any luck and I don't have the PHP knowledge to know if this is possible.
Any help would be greatly appreciated!
Comments
Comment #1
quicksketchThis is very possible, but requires a bit of PHP knowledge to get the task done. In the additional submission code, you can check the $form_values variable (doing a print_r($form_values) might help you get an idea of where everything is stored) and update any of those values as necessary. You could create hidden form elements for your totals, then set their values in the additional processing code. They'd then show up in the results pages and in the sent emails.
Comment #2
ghumpley commentedThanks for the info! Currently I'm sure this is still way over my head as I know I don't have the PHP knowledge to pull it off. I've done a little research to get me started so I'm sure I'll just have to put this on hold for now until I learn a bit more.
Comment #3
dabro commentedWhat am I doing wrong?
I am trying to do some calculations on submitted values, but I'm unable to get ahold of the values. I have a simple test form with a field named "value".
I've tried to print the submitted value in that field in the e-mail with:
I get nothing.
I tried printing the array:
print_r($form_values);I get nothing.I can print Server values fine:
print($_SERVER[SERVER_ADDR]);This works fine. For Example.I know there must be something very basic I'm not seeing, I'm far from fluent with PHP. Any help would be greatly appreciated. Thanks for the great module. Dave
Comment #4
quicksketchWhere are you putting the code? This needs to be used in the additional submit field under "Webform Advanced Options". You should be getting at least something.
Maybe, you should try printing to the message area with some code like this:
And if you still don't get anything you can try this to print out literally all available variables:
Comment #5
ccb621 commentedIs it not possible to print a calculated value in the confirmation message? I want to sum up some values and print them in the confirmation message. So far I have only been successful with using drupal_set_message() in the extra processing section. How can I use the values in the confirmation page, or setup the extra processing section so that its output is properly themed?
Comment #6
quicksketchOh boy. Okay now this is getting into something a little bit different. The submission message doesn't have access to the $form_values data any more because all the processing is done, then the user is forwarded to the confirmation message or page. The only thing you have access to on the confirmation page is the SID (submission ID). You can load the submission with:
Then you can pull out any necessary information from the $submission variable.
Comment #7
quicksketchClosing after lack of activity.