The following warnings occurred:
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.27 (Linux)
File Line Function
/global.php 783 errorHandler->error
/showthread.php 26 require_once
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.27 (Linux)
File Line Function
/global.php 783 errorHandler->error
/showthread.php 26 require_once
Warning [2] Undefined variable $newpmmsg - Line: 40 - File: global.php(841) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/global.php(841) : eval()'d code 40 errorHandler->error
/global.php 841 eval
/showthread.php 26 require_once
Warning [2] Undefined array key "style" - Line: 909 - File: global.php PHP 8.1.27 (Linux)
File Line Function
/global.php 909 errorHandler->error
/showthread.php 26 require_once
Warning [2] Undefined property: MyLanguage::$lang_select_default - Line: 5024 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 5024 errorHandler->error
/global.php 909 build_theme_select
/showthread.php 26 require_once
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions.php 5044 is_member
/global.php 909 build_theme_select
/showthread.php 26 require_once
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1370 fetch_forum_permissions
/showthread.php 137 forum_permissions
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined array key 1 - Line: 1415 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 1415 errorHandler->error
/inc/functions.php 1380 fetch_forum_permissions
/inc/functions.php 2909 forum_permissions
/showthread.php 621 build_forum_jump
Warning [2] Undefined property: MyLanguage::$ratings_update_error - Line: 5 - File: showthread.php(732) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/showthread.php(732) : eval()'d code 5 errorHandler->error
/showthread.php 732 eval
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions_user.php 844 is_member
/inc/functions_post.php 406 purgespammer_show
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "profilefield" - Line: 6 - File: inc/functions_post.php(474) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php(474) : eval()'d code 6 errorHandler->error
/inc/functions_post.php 474 eval
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "canonlyreplyownthreads" - Line: 660 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 660 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showimages" - Line: 741 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 741 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showvideos" - Line: 746 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 746 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions_user.php 844 is_member
/inc/functions_post.php 406 purgespammer_show
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "profilefield" - Line: 6 - File: inc/functions_post.php(474) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php(474) : eval()'d code 6 errorHandler->error
/inc/functions_post.php 474 eval
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "canonlyreplyownthreads" - Line: 660 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 660 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showimages" - Line: 741 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 741 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showvideos" - Line: 746 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 746 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions_user.php 844 is_member
/inc/functions_post.php 406 purgespammer_show
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "profilefield" - Line: 6 - File: inc/functions_post.php(474) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php(474) : eval()'d code 6 errorHandler->error
/inc/functions_post.php 474 eval
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "canonlyreplyownthreads" - Line: 660 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 660 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showimages" - Line: 741 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 741 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showvideos" - Line: 746 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 746 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "additionalgroups" - Line: 7162 - File: inc/functions.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions.php 7162 errorHandler->error
/inc/functions_user.php 844 is_member
/inc/functions_post.php 406 purgespammer_show
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "profilefield" - Line: 6 - File: inc/functions_post.php(474) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php(474) : eval()'d code 6 errorHandler->error
/inc/functions_post.php 474 eval
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "canonlyreplyownthreads" - Line: 660 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 660 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showimages" - Line: 741 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 741 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "showvideos" - Line: 746 - File: inc/functions_post.php PHP 8.1.27 (Linux)
File Line Function
/inc/functions_post.php 746 errorHandler->error
/showthread.php 1070 build_postbit
Warning [2] Undefined array key "invisible" - Line: 1506 - File: showthread.php PHP 8.1.27 (Linux)
File Line Function
/showthread.php 1506 errorHandler->error
Warning [2] Undefined variable $threadnotesbox - Line: 30 - File: showthread.php(1533) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/showthread.php(1533) : eval()'d code 30 errorHandler->error
/showthread.php 1533 eval
Warning [2] Undefined variable $addremovesubscription - Line: 79 - File: showthread.php(1533) : eval()'d code PHP 8.1.27 (Linux)
File Line Function
/showthread.php(1533) : eval()'d code 79 errorHandler->error
/showthread.php 1533 eval



FORUMS


The Form Tools forums are no longer active, but the old posts have been archived here. Please see the Help page on how to get help / report issues.

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PayPal demo: Multiple dollar selects.
#1
Hi all,

I've managed to get the PayPal demo form operational. Woo hoo! I've since extended it by adding three drop downs in place of the original "amount" select input found in the demo. I've been trying to figure out how to add the dollar values in the three drop downs for submission to PayPal.

I see that the original drop down has name="amount". With a bit of exploring I see the following code snippet in global_config.inc.php;
Code:
<input type="hidden" name="amount" value="<?php echo @$paypal[amount]?>" />

This tells me that PayPal requires the value "amount" which just so happens to be used in the demo drop down. Hey, Hey!

Now my drop down names are "session1", "session2" and "donate". How do I add these three selected values and feed them to PayPal via their @$paypal[amount] variable?

I suspect I can place the code in paypal_submit.php since this is the go-between from the form to PayPal. Where would it go? Kinda new to PHP so it would be awesome if you could provide some sample code.

I suspect responses to these questions would help a lot of users. If I figure it out before I get a response I'll post it here.

Thanks in advance,
Scott
Reply
#2
(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:

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 
Reply
#3
Hi Michael,

Open source software is wonderful. So many people willing to give good advice to those in need. Thank you for your response.

I looked at the Submission Pre-Parser module and thought that was more for submissions directly to FormTools. It is my understanding (Ben, correct me if I am wrong!) that the PayPal code (through paypal_submit.php) talks directly to PayPal and only after success does it add the data to FormTools. If the user cancels their PayPal payment then no entry is made in FormTools.

That being said, your code looks like an excellent starting point for my needs. Unlike the donate select, the session1 and session2 selects have a default hyphen so I would have to cater to the in the IF statement.
Code:
<select id ="session1" name="session1">
    <option value="-" selected="selected">-</option>
    <option value="25">25</option>
    <option value="30">30</option>
    <option value="35">35</option>
    <option value="40">40</option>
</select>

With a minor modification to you code I have;

PHP Code:
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 

I will experiment with adding this to the top of paypal_submit.php just after the require statements. I'm guessing this is the correct place to put it. If anyone has a better idea, please let me know.

But first I have an irritating Error Code: #100 problem when adding the new form even though I have the form_id and mode correctly set in library.php and I have been clearing the sessions by reloading the success.php page before doing the initializing form submission.
Code:
// your Form Tools form ID
$pp["form_id"] = 13;

// the Form Tools submission mode
$pp["mode"] = "initialize";
//$pp["mode"] = "live";

Worked fine when I set up the original PayPal demo and I have no problem when using the standard API approach in other projects that don't use PayPal. Not certain how to troubleshoot this one.

Michael, thanks again for your help.
Scott
Reply
#4
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.

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! Smile

- Ben
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)