Jul 10th, 2010, 9:40 AM
Hi Scott,
Sounds like you're making progress, at least!
For the 100 Error, double-check that you're not passing along another form ID via a hidden field in your form. Most Form Tools forms work like that, so it's possible that there's a value there that's overwriting the $pp["form_id"] value. That's tripped me up on a couple of occasions. If that doesn't help, post us back.
Michael - excellent post! Yes, using the Submission Pre-Parser is the definitely the best approach for changing or combining any form data prior to it getting into Form Tools. But PayPal integrations are ever so slightly different and it won't completely work in this instance.
It's actually a rather subtle problem, so to better explain, here's a quick run-down of the process:
(1) The form. At the top of this page - and the second paypal_submit.php file - is a function called ft_api_init_form_page(). This does the job of keeping track of what's been submitted up to that point, and establish a bucket of storage ("sessions") where the form info should be logged.
Now, after the user fills in the form & clicks submit, the form submits the data to itself, which then (a) stores the latest POST data via ft_api_ini_form_page() and (b) calls ft_api_process_form(). At that point, the Submission Pre-Parser module kicks into action and sums up the total and stores it in "amount". Then, assuming your Form Tools form has an "amount" database field, it'll be stored in the database. Now even though your code to tot up the amount has doctored the POST variable, it won't be remembered!
You see, the ftp_api_process_form() THEN redirects to the paypal_submit.php page, and doesn't forward the POST content at that point. The assumption is that the ft_api_init_form_page() has already done the job of saving the latest POST info in sessions, so on the paypal_submit.php page, it's retrieved from there instead.
Problem!
So Scott, I'd suggest moving that code you wrote for the pre-parser right into the top of your form before ft_api_init_form_page() is called. What THAT will do is update the POST info prior to it being stored in sessions, to that after the script redirects to paypal_submit.php, it'll have the latest & greatest POST content - including your "amount" key.
Clear as mud...? Eesh, sorry. Hope it makes sense. But here's some sample PHP of how I'd add it to your form page.
Lastly, delete the pre-parser rule. The above should take care of it for both Form Tools' and the PayPal form's benefit.
Good luck!
- Ben
Sounds like you're making progress, at least!
For the 100 Error, double-check that you're not passing along another form ID via a hidden field in your form. Most Form Tools forms work like that, so it's possible that there's a value there that's overwriting the $pp["form_id"] value. That's tripped me up on a couple of occasions. If that doesn't help, post us back.
Michael - excellent post! Yes, using the Submission Pre-Parser is the definitely the best approach for changing or combining any form data prior to it getting into Form Tools. But PayPal integrations are ever so slightly different and it won't completely work in this instance.
It's actually a rather subtle problem, so to better explain, here's a quick run-down of the process:
(1) The form. At the top of this page - and the second paypal_submit.php file - is a function called ft_api_init_form_page(). This does the job of keeping track of what's been submitted up to that point, and establish a bucket of storage ("sessions") where the form info should be logged.
Now, after the user fills in the form & clicks submit, the form submits the data to itself, which then (a) stores the latest POST data via ft_api_ini_form_page() and (b) calls ft_api_process_form(). At that point, the Submission Pre-Parser module kicks into action and sums up the total and stores it in "amount". Then, assuming your Form Tools form has an "amount" database field, it'll be stored in the database. Now even though your code to tot up the amount has doctored the POST variable, it won't be remembered!
You see, the ftp_api_process_form() THEN redirects to the paypal_submit.php page, and doesn't forward the POST content at that point. The assumption is that the ft_api_init_form_page() has already done the job of saving the latest POST info in sessions, so on the paypal_submit.php page, it's retrieved from there instead.
Problem!
So Scott, I'd suggest moving that code you wrote for the pre-parser right into the top of your form before ft_api_init_form_page() is called. What THAT will do is update the POST info prior to it being stored in sessions, to that after the script redirects to paypal_submit.php, it'll have the latest & greatest POST content - including your "amount" key.
Clear as mud...? Eesh, sorry. Hope it makes sense. But here's some sample PHP of how I'd add it to your form page.
PHP Code:
<?php
$curr_folder = dirname(__FILE__);
require_once("$curr_folder/includes/library.php");
require_once("../global/short_library.php");
// if the user just posted something to the page, it's safe to assume the form
// was just submitted.
if (isset($_POST))
{
if (isset($_POST["session1"]) && ($_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"]) && ($_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
}
$fields = ft_api_init_form_page($pp["form_id"], $pp["mode"]);
if ($pp["mode"] == "initialize")
{
$params = array(
"submit_button" => "donate",
"next_page" => "success.php",
"form_data" => $_POST,
"finalize" => true
);
}
else
{
$params = array(
"submit_button" => "donate",
"next_page" => "paypal_submit.php",
"form_data" => $_POST
);
}
ft_api_process_form($params);
Lastly, delete the pre-parser rule. The above should take care of it for both Form Tools' and the PayPal form's benefit.
Good luck!
- Ben