Jul 5th, 2010, 5:32 PM
(This post was last modified: Jul 5th, 2010, 5:33 PM by michael.ka.)
(I don’t know about the details of making PayPal work with Form Tools so I’m going to assume that you are correct and that it is indeed necessary to submit an 'amount' in order to make PayPal work.)
The Submission Pre-Parser module should be able to solve your problem. It allows you (among other things) to combine fields.
Here is the example code for combining fields:
All this does is check whether the three submitted input fields with the names 'phone_1', 'phone_2' and 'phone_3' are set and not empty (first three lines) and if that is the case it combines them and submits them with the name 'phone' (last line).
Just change 'phone_1', 'phone_2', 'phone_3' and 'phone' to 'session1', 'session2', 'donate' and 'amount' respectively and you are already halfway there. In this example, however, strings are combined. You don’t want to do that, you want to convert strings to numbers and add them together. You might also want to perform some sanity checks, probably different sanity checks than in this case (if one of the values in this example isn’t set, 'phone' just isn’t submitted. In your case 'amount' wouldn’t be submitted which would mean that PayPal doesn’t get the value).
Now, I don’ know PHP, so I can’t tell you with authority about the details of making this work. It should amount to some fairly trivial PHP code. Google tells me that converting a string to integer works something like this:
Here’s my version of how your Submission Pre-Parser rule might look like. Keep in mind that I never learned anything about PHP so this might fail pathetically or be ridiculously wrong. Take it as a starting point.
I assumed that you are using integers for the dollar amounts, you would have to convert them to floats if that isn’t the case. I also assumed that no selection by the user for a particular drop down implies a dollar value of zero for that particular drop down.
You probably should do some server side validation beforehand as to whether the user selected as least one value in on drop down. I nevertheless built in a check to handle that case here.
The Submission Pre-Parser module should be able to solve your problem. It allows you (among other things) to combine fields.
Here is the example code for combining fields:
PHP Code:
if ( (isset($_POST["phone_1"]) && !empty($_POST["phone_1"])) &&
(isset($_POST["phone_2"]) && !empty($_POST["phone_2"])) &&
(isset($_POST["phone_3"]) && !empty($_POST["phone_3"])) )
{
$_POST["phone"] = "{$_POST["phone_1"]}-{$_POST["phone_2"]}-{$_POST["phone_3"]}";
}
All this does is check whether the three submitted input fields with the names 'phone_1', 'phone_2' and 'phone_3' are set and not empty (first three lines) and if that is the case it combines them and submits them with the name 'phone' (last line).
Just change 'phone_1', 'phone_2', 'phone_3' and 'phone' to 'session1', 'session2', 'donate' and 'amount' respectively and you are already halfway there. In this example, however, strings are combined. You don’t want to do that, you want to convert strings to numbers and add them together. You might also want to perform some sanity checks, probably different sanity checks than in this case (if one of the values in this example isn’t set, 'phone' just isn’t submitted. In your case 'amount' wouldn’t be submitted which would mean that PayPal doesn’t get the value).
Now, I don’ know PHP, so I can’t tell you with authority about the details of making this work. It should amount to some fairly trivial PHP code. Google tells me that converting a string to integer works something like this:
PHP Code:
settype($foo, "integer");
Here’s my version of how your Submission Pre-Parser rule might look like. Keep in mind that I never learned anything about PHP so this might fail pathetically or be ridiculously wrong. Take it as a starting point.
I assumed that you are using integers for the dollar amounts, you would have to convert them to floats if that isn’t the case. I also assumed that no selection by the user for a particular drop down implies a dollar value of zero for that particular drop down.
You probably should do some server side validation beforehand as to whether the user selected as least one value in on drop down. I nevertheless built in a check to handle that case here.
PHP Code:
if (isset($_POST["session1"]) && !empty($_POST["session1"]))
settype($_POST["session1"], "integer"); // convert the value of session1 to integer if the user set one
else
$_POST["session1"] = 0; // otherwise set the value to 0
if (isset($_POST["session2"]) && !empty($_POST["session2"]))
settype($_POST["session2"], "integer"); // convert the value of session1 to integer if the user set one
else
$_POST["session2"] = 0; // otherwise set the value to 0
if (isset($_POST["donate"]) && !empty($_POST["donate"]))
settype($_POST["donate"], "integer"); // convert the value of donate to integer if the user set one
else
$_POST["session2"] = 0; // otherwise set the value to 0
$added_amount = $_POST["session1"] + $_POST["session2"] + $_POST["donate"] // add the three values together and store them in a variable
if ($added_amount == 0)
/* you presumably don’t want to continue to PayPal if the user didn’t select anything,
add code to handle that case here */
else
$_POST["amount"] = $added_amount; // submit the combined values as amount