473,422 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,422 software developers and data experts.

Submit a form & go to the new page after validate

Hi,

A difficult question.

I have a form that I used to submit to https://www. paypal.com/cgi-bin/
webscr
<form action="https://www. paypal.com/cgi-bin/webscr" method="post">

Now I need to validate some inputs of this form, so I submit it to a
PHP page in my own server first.
<form action="paypal_upgrade_checking.php" method="post">

After validate, I need to submit the form again to https://www.
paypal.com/cgi-bin/webscr
I write a piece of PHP code but it failed. The browse is still in
paypal_upgrade_checking.php, it doesn't go to the new page.
I wonder whether there is a way to do it.
<?
....
$buf = '';

$req = '';

foreach ($_POST as $key =$value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

$header="";
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
print "HTTP ERROR<br/>$errno<br/>$errstr";
exit();
} else {
fputs ($fp, $header . $req);
while(!feof($fp)) {
$buf.=fgets($fp,1024);
}
fclose($fp);
echo $buf;
}
?>

Thank you
Kelvin

Jul 13 '07 #1
10 6825
kelvin wrote:
Hi,

A difficult question.

I have a form that I used to submit to https://www. paypal.com/cgi-bin/
webscr
<form action="https://www. paypal.com/cgi-bin/webscr" method="post">

Now I need to validate some inputs of this form, so I submit it to a
PHP page in my own server first.
<form action="paypal_upgrade_checking.php" method="post">

After validate, I need to submit the form again to https://www.
paypal.com/cgi-bin/webscr
I write a piece of PHP code but it failed. The browse is still in
paypal_upgrade_checking.php, it doesn't go to the new page.
I wonder whether there is a way to do it.
<?
...
$buf = '';

$req = '';

foreach ($_POST as $key =$value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

$header="";
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
print "HTTP ERROR<br/>$errno<br/>$errstr";
exit();
} else {
fputs ($fp, $header . $req);
while(!feof($fp)) {
$buf.=fgets($fp,1024);
}
fclose($fp);
echo $buf;
}
?>

Thank you
Kelvin
Kelvin,

Do it the easy way - use CURL to do your posting.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 13 '07 #2
Thank you, but there is no curl on my web hosting server.
Is it possible to use something like javascript together if it is too
difficult to use PHP only?
Thank you,
Kelvin

Jul 13 '07 #3
ED

"kelvin" <ke*******@yahoo.com.cnwrote in message
news:11**********************@m37g2000prh.googlegr oups.com...
Hi,

A difficult question.

I have a form that I used to submit to https://www. paypal.com/cgi-bin/
webscr
<form action="https://www. paypal.com/cgi-bin/webscr" method="post">

Now I need to validate some inputs of this form, so I submit it to a
PHP page in my own server first.
<form action="paypal_upgrade_checking.php" method="post">

After validate, I need to submit the form again to https://www.
paypal.com/cgi-bin/webscr
I write a piece of PHP code but it failed. The browse is still in
paypal_upgrade_checking.php, it doesn't go to the new page.
I wonder whether there is a way to do it.
<?
...
$buf = '';

$req = '';

foreach ($_POST as $key =$value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

$header="";
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
print "HTTP ERROR<br/>$errno<br/>$errstr";
exit();
} else {
fputs ($fp, $header . $req);
while(!feof($fp)) {
$buf.=fgets($fp,1024);
}
fclose($fp);
echo $buf;
}
?>

Thank you
Kelvin
Hi Kelvin,
Presuming that you want to redirect the browser a quick easy fix may be to
use GET instead of POST to submit to paypal (IIRC they support both
methods):
ie, using $req from your existing code:

$url = 'https://www.paypal.com/cgi-bin/webscr?'.$req
header("Location: $url");
exit;

cheers,
ED


Jul 13 '07 #4
On 13 Jul, 03:44, kelvin <kelvin...@yahoo.com.cnwrote:
Hi,

A difficult question.

I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
webscr
<form action="https://www. paypal.com/cgi-bin/webscr" method="post">

Now I need to validate some inputs of this form, so I submit it to a
PHP page in my own server first.
<form action="paypal_upgrade_checking.php" method="post">

After validate, I need to submit the form again tohttps://www.
paypal.com/cgi-bin/webscr
I write a piece of PHP code but it failed. The browse is still in
paypal_upgrade_checking.php, it doesn't go to the new page.
I wonder whether there is a way to do it.

<?
...
$buf = '';

$req = '';

foreach ($_POST as $key =$value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

$header="";
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
print "HTTP ERROR<br/>$errno<br/>$errstr";
exit();
} else {
fputs ($fp, $header . $req);
while(!feof($fp)) {
$buf.=fgets($fp,1024);
}
fclose($fp);
echo $buf;
}
?>

Thank you
Kelvin
This code will cause the sver to communicate with paypal, it won't
affect the browser.

You could send the form to the clinet and send an onload() script to
automatically submit it.

Jul 13 '07 #5
kelvin wrote:
Thank you, but there is no curl on my web hosting server.
Is it possible to use something like javascript together if it is too
difficult to use PHP only?
Thank you,
Kelvin
Don't know. Try a javascript newsgroup.

Or, if your hosting company won't install CURL, get another host.
They're are enough good ones around, and there's no reason to fight what
can be easily fixed.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 13 '07 #6
Captain Paralytic wrote:
On 13 Jul, 03:44, kelvin <kelvin...@yahoo.com.cnwrote:
>Hi,

A difficult question.

I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
webscr
<form action="https://www. paypal.com/cgi-bin/webscr" method="post">

Now I need to validate some inputs of this form, so I submit it to a
PHP page in my own server first.
<form action="paypal_upgrade_checking.php" method="post">

After validate, I need to submit the form again tohttps://www.
paypal.com/cgi-bin/webscr
I write a piece of PHP code but it failed. The browse is still in
paypal_upgrade_checking.php, it doesn't go to the new page.
I wonder whether there is a way to do it.

<?
...
$buf = '';

$req = '';

foreach ($_POST as $key =$value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

$header="";
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
print "HTTP ERROR<br/>$errno<br/>$errstr";
exit();
} else {
fputs ($fp, $header . $req);
while(!feof($fp)) {
$buf.=fgets($fp,1024);
}
fclose($fp);
echo $buf;
}
?>

Thank you
Kelvin

This code will cause the sver to communicate with paypal, it won't
affect the browser.

You could send the form to the clinet and send an onload() script to
automatically submit it.
The problem with that is he won't know if the transaction succeeded or not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 13 '07 #7
On 13 Jul, 12:57, Jerry Stuckle <jstuck...@attglobal.netwrote:
Captain Paralytic wrote:
On 13 Jul, 03:44, kelvin <kelvin...@yahoo.com.cnwrote:
Hi,
A difficult question.
I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
webscr
<form action="https://www. paypal.com/cgi-bin/webscr" method="post">
Now I need to validate some inputs of this form, so I submit it to a
PHP page in my own server first.
<form action="paypal_upgrade_checking.php" method="post">
After validate, I need to submit the form again tohttps://www.
paypal.com/cgi-bin/webscr
I write a piece of PHP code but it failed. The browse is still in
paypal_upgrade_checking.php, it doesn't go to the new page.
I wonder whether there is a way to do it.
<?
...
$buf = '';
$req = '';
foreach ($_POST as $key =$value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$header="";
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
print "HTTP ERROR<br/>$errno<br/>$errstr";
exit();
} else {
fputs ($fp, $header . $req);
while(!feof($fp)) {
$buf.=fgets($fp,1024);
}
fclose($fp);
echo $buf;
}
?>
Thank you
Kelvin
This code will cause the sver to communicate with paypal, it won't
affect the browser.
You could send the form to the clinet and send an onload() script to
automatically submit it.

The problem with that is he won't know if the transaction succeeded or not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attglobal.net
==================- Hide quoted text -

- Show quoted text -
But my reading of what he said is the he wants to validate data in the
form before posting it and redirecting the user to the paypal site.
Indeed he specifically says that the user stays on his page, rather
than being sent to the paypal page.

So the validation is to be done BEFORE sending the form (and the user)
to the paypal site.

I would tend to do the validation by javascript if possible, or if I
had to do it serverside I'd use AJAX methods.
Jul 13 '07 #8
Captain Paralytic wrote:
>
But my reading of what he said is the he wants to validate data in the
form before posting it and redirecting the user to the paypal site.
Indeed he specifically says that the user stays on his page, rather
than being sent to the paypal page.

So the validation is to be done BEFORE sending the form (and the user)
to the paypal site.

I would tend to do the validation by javascript if possible, or if I
had to do it serverside I'd use AJAX methods.

Either of which fail if JS is disabled, for instance.

I've got one site I took over from another webmaster which does this.
It's written in VBScript/ASP, so CURL isn't an option. The problem is
it requires additional work for the admin people to process the request
once payment has been completed. And this time can really add up.

Another PHP site I have which uses CURL is fully automated. No
additional work to process the payment required at all.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jul 13 '07 #9
On Jul 13, 4:10 am, "ED" <e...@example.comwrote:
"kelvin" <kelvin...@yahoo.com.cnwrote in message

news:11**********************@m37g2000prh.googlegr oups.com...
Hi,
A difficult question.
I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
webscr
<form action="https://www. paypal.com/cgi-bin/webscr" method="post">
Now I need to validate some inputs of this form, so I submit it to a
PHP page in my own server first.
<form action="paypal_upgrade_checking.php" method="post">
After validate, I need to submit the form again tohttps://www.
paypal.com/cgi-bin/webscr
I write a piece of PHP code but it failed. The browse is still in
paypal_upgrade_checking.php, it doesn't go to the new page.
I wonder whether there is a way to do it.
<?
...
$buf = '';
$req = '';
foreach ($_POST as $key =$value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$header="";
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
print "HTTP ERROR<br/>$errno<br/>$errstr";
exit();
} else {
fputs ($fp, $header . $req);
while(!feof($fp)) {
$buf.=fgets($fp,1024);
}
fclose($fp);
echo $buf;
}
?>
Thank you
Kelvin

Hi Kelvin,
Presuming that you want to redirect the browser a quick easy fix may be to
use GET instead of POST to submit to paypal (IIRC they support both
methods):
ie, using $req from your existing code:

$url = 'https://www.paypal.com/cgi-bin/webscr?'.$req
header("Location: $url");
exit;

cheers,
ED
It works for me.

Thank you a lot,
Kelvin

Jul 14 '07 #10
On Jul 13, 4:10 am, "ED" <e...@example.comwrote:
"kelvin" <kelvin...@yahoo.com.cnwrote in message

news:11**********************@m37g2000prh.googlegr oups.com...
Hi,
A difficult question.
I have a form that I used to submit tohttps://www. paypal.com/cgi-bin/
webscr
<form action="https://www. paypal.com/cgi-bin/webscr" method="post">
Now I need to validate some inputs of this form, so I submit it to a
PHP page in my own server first.
<form action="paypal_upgrade_checking.php" method="post">
After validate, I need to submit the form again tohttps://www.
paypal.com/cgi-bin/webscr
I write a piece of PHP code but it failed. The browse is still in
paypal_upgrade_checking.php, it doesn't go to the new page.
I wonder whether there is a way to do it.
<?
...
$buf = '';
$req = '';
foreach ($_POST as $key =$value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
$header="";
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);
if (!$fp) {
// HTTP ERROR
print "HTTP ERROR<br/>$errno<br/>$errstr";
exit();
} else {
fputs ($fp, $header . $req);
while(!feof($fp)) {
$buf.=fgets($fp,1024);
}
fclose($fp);
echo $buf;
}
?>
Thank you
Kelvin

Hi Kelvin,
Presuming that you want to redirect the browser a quick easy fix may be to
use GET instead of POST to submit to paypal (IIRC they support both
methods):
ie, using $req from your existing code:

$url = 'https://www.paypal.com/cgi-bin/webscr?'.$req
header("Location: $url");
exit;

cheers,
ED
It works for me too.

Thank you a lot,
Kelvin

Jul 14 '07 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Jimbo | last post by:
I am trying to right a script so that the "submit button" only appears when certain criteria has been met. I have tried putting it in an IF statement, without any luck. Maybe a function would allow...
5
by: lsarg | last post by:
i've been trying forever to figure out a way to use a regular text link in place of a submit button at the bottom of this. can't get it. i'm just starting to learn php, so i'm stuck. any help at...
3
by: Matt | last post by:
In the following code, I have 2 questions regarding submit button with image. 1) Does this code <input type="image" name="populate" src="populate.gif"> behave the same as an HTML submit button...
15
by: M Smith | last post by:
I have a form I want to submit to itself. I want to be able to type in a list of numbers and submit the form and have that list show up on the same form under the text box I typed them into and...
6
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form...
4
by: gimme_this_gimme_that | last post by:
Hi, This is sort of a : How to build a Yes/No dialog box qquestion. Or perhaps a question about getting javascript variables from a pop-up window and processing them on a submit. This is...
4
by: John Boy | last post by:
Hi, Can anyone help. This is really doing my nut in. 3 years ASP exp. and now doing .DOT which is a step in the wrong direction. Basically I am left with the code of a guy who has left. When I...
5
by: holy moly | last post by:
Hello, I have been trying to get this JS form validation code to work ad nauseam... it won't validate, stop if required and submit. The best I managed was to get it to display an empty...
5
by: sumeetmakkar | last post by:
Hi all, I am a begineer and working on a project. Facing trouble linking a submit buuton to a page of my choice.Script i am using is: <SCRIPT language=JavaScript><!-- function validate(form) {...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.