Page 1 of 1
Doing 2 things w/ 1 form?
Posted: Tue Apr 08, 2003 4:13 am
by daisysf
I'm trying to log when someone SUBMITs an order.....
In other words;
When someone Submits "Script #1",
I'd like "Script #2" to be executed before "Script #1",
is sent to "Paypal".
I'm thinking it could be done using "Code #1" or "Code #2",
before "Script #2".
What I need to know is, how to make this possible?
Script #1: (PayPal Script)
Code: Select all
echo "<form target='paypal' action='https://www.paypal.com/cgi-bin/webscr' method='post'>\n";
echo "<input type='hidden' name='cmd' value='_cart'>\n";
....
echo "<input type='submit' name='submit' value='Purchase This Item'>\n";
Script #2: (Log Script)
Code: Select all
{
$logfile = "logfile.txt";
$logthis = $row->item_num.$row->item_name." FOR $".$row->Price."+ $".$row->shipping." TOTALING $".$row->total_price;
$fh = fopen($logfile, "a");
fwrite ($fh, "$logthis\n");
fclose ($fh);
}
Code #1:
Code #2:
I was thinking I might have to change "action=" to <? PHP_SELF ?>, but if I do,
I don't know how to submit the data to '
https://www.paypal.com/cgi-bin/webscr'.
Could anyone give me any pointers, or help shed some light on this project?
btw, I'm using my ISP's PHP/4.2.3 on Apache/1.3.27 and mySQL db.
I'M LOOKING FOR ANY PHP PROGRAMMER TO
HELP ME WITH THE CODES ABOVE,
I DO
NOT WANT TO RECODE MY WHOLE SCRIPT OR USE PayPal's IPN.
Posted: Tue Apr 08, 2003 11:44 am
by bznutz
It's simple.
Use one script to do both things.
The beginning of the script logs the submission.
The end of the script sends the data to paypal.
What part of this causes you confusion?
Posted: Tue Apr 08, 2003 2:09 pm
by BDKR
bznutz wrote:It's simple.
Use one script to do both things.
The beginning of the script logs the submission.
The end of the script sends the data to paypal.
Better yet, submit to paypal first. That way, if it fails, you can also log that it failed as opposed to assuming it worked.
And for bznutz, what part of that causes you confusion?
BDKR!
Simple 4 you, but Hard 4 me
Posted: Tue Apr 08, 2003 3:18 pm
by daisysf
bznutz,
You got it, that's what I want, but HOW do I get it ?
HERE IS THE CONFUSION:
1. Which "Code" do I start with (if isset or if submit)?
2. Must I change the "action=" in the paypal script to PHP_SELF?
3. If I must, how do I get it sent to the old paypal "action" after logging?
4. Do I use "return true/false" at all, if so where?
5. Do I use a (Do/While) instead of PHP_SELF?
6. Could you show me how SIMPLE it is, WITH EXAMPLES?
7. REMEMBER; I Only Want To Log It, ON Submit, NOT ON Load.
BDKR,
I would like to log the "SUBMIT" before PAYPAL gets the data.
Example:
user Clicks "Submit",
(in background, invisible to user) Log Item/Price into logfile.txt
(once logged, user sees) PayPal's Shopping Cart secured POP-UP Window,
(indicating) Paypal rcvd the data that was submitted
This way I would know each time someone EXITS my site,
TO Paypal's site, and for which Product and it's Price at that time.
THANK YOU BOTH 4 UR input.
Re: Simple 4 you, but Hard 4 me
Posted: Tue Apr 08, 2003 10:41 pm
by bznutz
daisysf wrote:bznutz,
You got it, that's what I want, but HOW do I get it ?
HERE IS THE CONFUSION:
1. Which "Code" do I start with (if isset or if submit)?
2. Must I change the "action=" in the paypal script to PHP_SELF?
3. If I must, how do I get it sent to the old paypal "action" after logging?
4. Do I use "return true/false" at all, if so where?
5. Do I use a (Do/While) instead of PHP_SELF?
6. Could you show me how SIMPLE it is, WITH EXAMPLES?
7. REMEMBER; I Only Want To Log It, ON Submit, NOT ON Load.
BDKR,
I would like to log the "SUBMIT" before PAYPAL gets the data.
Example:
user Clicks "Submit",
(in background, invisible to user) Log Item/Price into logfile.txt
(once logged, user sees) PayPal's Shopping Cart secured POP-UP Window,
(indicating) Paypal rcvd the data that was submitted
This way I would know each time someone EXITS my site,
TO Paypal's site, and for which Product and it's Price at that time.
THANK YOU BOTH 4 UR input.
You log it only when the post varialbes are set. In otherwords, the form was submitted, so the submit button was posted to the php script, so submit to paypal and then log it.
Check if(isset($_POST['submitname']));
If true, log it
if false, don't log it.
Got it?
Posted: Tue Apr 08, 2003 11:17 pm
by daisysf
This code don't look right:
Code: Select all
Check if(isset($_POST['submitname']));
If true, log it
if false, don't log it.
or where you trying to say?:
Code: Select all
<?php
if (isset($_POST['submit']))
{
$logfile = "logfile.txt";
$logthis = $row->item_num.$row->item_name." FOR $".$row->Price."+ $".$row->shipping." TOTALING $".$row->total_price;
$fh = fopen($logfile, "a");
fwrite ($fh, "$logthis\n");
fclose ($fh);
}
else
{
echo "<form target='paypal' action='https://www.paypal.com/cgi-bin/webscr' method='post'>\n";
echo "<input type='hidden' name='cmd' value='_cart'>\n";
....
echo "<input type='submit' name='submit' value='Purchase This Item'>\n";
echo "</form>\n";
}
?>
So if false, it echo's the FORM ?
Wouldn't that reproduce the form multiple times in browser until submit is clicked on?
Thanks for bearing with me....
Posted: Wed Apr 09, 2003 6:47 am
by DeGauss
Code: Select all
<?
if ($_POST["task"]=="go") {
$logfile = "logfile.txt";
$logthis = $row->item_num.$row->item_name." FOR $".$row->Price."+ $".$row->shipping." TOTALING $".$row->total_price;
$fh = fopen($logfile, "a");
fwrite ($fh, "$logthis\n");
fclose ($fh);
header("Location: ".$_SERVER["PHP_SELF"]."?task=done");
} else {
if (!$_GET["task"]) {
echo "<form target='paypal' action='https://www.paypal.com/cgi-bin/webscr' method='post'>\n";
echo "<input type='hidden' name='cmd' value='_cart'>\n";
....
echo "<input type='submit' name='submit' value='Purchase This Item'>\n";
echo "<input type='hidden' name='task' value='go'>\n";
} elseif ($_GET["task"]=="done") {
echo "Payment probably received, thanks.";
}
?>
Probably what you're looking for.
I'm not sure, but it looks like in the code that deals with the log entry you're dealing with class variables, but then i don't want to make myself look dumb by not knowing about some magic new kind of variable.
I hate echo.
Enjoy!
Posted: Thu Apr 10, 2003 12:55 am
by daisysf
Neither of the last 2 scripts Executes/Produces a logfile".txt", They only pop-up PayPal window and submits to PayPal. I even tried switching the action and location var's that made it worse. I got a pop-up flash and nothing was submited or logged. I'm loosing hope on this project.