The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined array key "avatartype" - Line: 783 - File: global.php PHP 8.1.28 (Linux)
|
PayPal demo: Multiple dollar selects. - Printable Version +- Form Tools (https://forums.formtools.org) +-- Forum: Form Tools (https://forums.formtools.org/forumdisplay.php?fid=1) +--- Forum: General Discussion (https://forums.formtools.org/forumdisplay.php?fid=5) +--- Thread: PayPal demo: Multiple dollar selects. (/showthread.php?tid=771) |
PayPal demo: Multiple dollar selects. - Scott - Jul 4th, 2010 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 RE: PayPal demo: Multiple dollar selects. - michael.ka - Jul 5th, 2010 (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"])) && 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"])) RE: PayPal demo: Multiple dollar selects. - Scott - Jul 6th, 2010 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"> With a minor modification to you code I have; PHP Code: if (isset($_POST["session1"]) && ($_POST[session1] != "-" )) 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 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 RE: PayPal demo: Multiple dollar selects. - Ben - Jul 10th, 2010 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 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 |