I'm trying to add additional Processing to Webform. I want to multiply the values of two fields and place the result in a hidden field. Then, all the fields (including the hidden with the new value) should be added to the database.
I've been searching Drupal forums and Webform issues and I cannot seem to find anything to help me out. I found a book page about Webform Additional Submission Snippets at http://drupal.org/handbook/modules/webform/submission-code and it helped me out a little. I still cannot get the code to work. The following code results in this error "Parse error: syntax error, unexpected T_VARIABLE in /home/cerutis/public_html/sites/all/modules/webform/webform.module(1657) : eval()'d code on line 5"
// form components
$component_1_key = 'number_of_guests'
$component_1_cid = 1;
$component_1_value = $form_values['submitted'][$component_1_cid];
$component_3_key = 'meal_options'
$component_3_cid = 3;
$component_3_value = $form_values['submitted'][$component_3_cid];
$component_4_key = 'total_price'
$component_4_cid = 4;
$price = 0;
// find total price
$price = $component_1_value * $component_3_value;
// The First Name field is within a fieldset for "Name".
// Updating this value will set the value in the e-mail.
$form_values['submitted_tree']['name'][$component_4_key] = $price;
// Despite the field being in a fieldset, in the submitted array,
// it is identified directly by the component CID.
// Updating this value will set the value in the database.
$form_values['submitted'][$component_4_cid] = $price;
Also, sometimes the field to be multiplied will be a regular textfield, and others it will be a select listbox with the option to select multiple values. Step two would be figuring out how I can multiply the first component (number of guests) by each value selected in one select listbox. First I need to figure out how to multiply two textfields though.
Comments
Comment #1
kitsunechan commentedOk, so I'm assuming the problem is with the way I'm trying to get the submitted value of the form component.
If this works to set a value (per the example at the link above):
Then why doesn't this work to get the submitted value?
Comment #2
kitsunechan commentedI've abandoned using Webforms for this client, but would still like to learn how to use additional processing for future clients. Webforms is a great module for simple forms. I like this module a lot. It breaks my heart that I can't use it for anything else though. At the simplest level all I want to do is add, multiply, etc two fields and output the results. It's a shame that I can't do that with Webform. I guess I'll just make forms in php somewhere else on the server, iframe them into the body of a node, and make a separate database for my forms.
Comment #3
xayberoptix commentedsubscribe
Comment #4
sunshinee commentedThis may be a simpler application than you were looking for, but I've had success using the SESSION variables. Set session variable(s) in 'Additional Processing' on the webform node. Redirect the form to a node, rather than displaying a confirmation message. Then you can retrieve the session variable(s) and do something with them on the REDIRECT page. In this case, we sold tickets for an event at $20 per person.
**In the Webform "Additional Processing" Field**
**In the body field of the redirect/confirmation page**
I'm not good enough to tell you if this is the proper way, but I've had good success with similar applications.
~Joy
Comment #5
guislutavo commentedI've create a hidden component named "age" wich stores the age based in the data from the component "birth_date" (a date type component, so this is an array of day, month and year). The age is calculated by the subtraction of the year in the "birth_date" array from the current year. In the Additional Processing, I've put this:
The "23" number is the $sid ID of the "age" component. Maybe you could use this, it works, but i'm newbie, and I dont know exactly why. I simply used this: http://drupal.org/node/211143
Comment #6
miratopiantech commented@kitsunechan,
Just solved a similar problem.
Though, I'm unsure about the error message or why it points to line 5, I notice something about this statement of your code:
$form_values['submitted_tree']['name'][$component_4_key] = $price;.. the part that doesn't seem to belong here is ['name'], as this says your "price" field is part of a fieldset called 'name' - that'd sound odd. In the example where you based your code from, the firstname 'Bob' is rightfully placed into a field, which is part of a fieldset 'name'.
So, if you haven't declared a fieldset that includes the "price" field you should only have two []s in the statement:
$form_values['submitted_tree'][$component_4_key] = $price;Hope I've helped you but I'm pretty new to this. Only solved my own problem after scouting around for ages, and flipping between this page and the handbook one you pointed out (thanks, btw).
Comment #7
maddentim commented@kitsunechan, not sure if you ever found answer so I thought I would suggest one. when you say that one variable is equal to another, it can be a little misleading. When you start the two variables are usually not the same. the equals really means one variables value is changed to be equal to the other. This means that the order is critical. The left side stays the same and the right changes. In your case,
component_3_value is the one you want to change. It is likely to be null when you start, so what you are saying is whatever the user put in the form, change it to be blank. Make sense?
In my case, I found your post because I was looking for a way to have a user complete my webform (and do all the things that like the emails, validation and additional processing that I need done), and then in the additional processing, create a new node for a master database. Looking for examples of what others might have experienced...
Comment #8
quicksketchClosing after lack of activity.
Comment #9
vignesh.bohar commentedHello ,
Any could sort me out , i have created a webform which contains few fields.
for example a feedback form , if i submit the form , with the posted data it need to create a XML and that xml need to interface with the Webservice which contains the form values .
Ideas appreciated ,
Thanks in advance
Comment #10
hanno commentedchanged the title back to the original one. @vignes.bohar please open a new issue for your question as this is not related to the discussion above.