473,769 Members | 2,376 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_checkin g.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(strip slashes($value) );
$req .= "&$key=$val ue";
}

$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.p aypal.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 6853
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_checkin g.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(strip slashes($value) );
$req .= "&$key=$val ue";
}

$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.p aypal.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*******@attgl obal.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*******@yaho o.com.cnwrote in message
news:11******** **************@ m37g2000prh.goo glegroups.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_checkin g.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(strip slashes($value) );
$req .= "&$key=$val ue";
}

$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.p aypal.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("Locatio n: $url");
exit;

cheers,
ED


Jul 13 '07 #4
On 13 Jul, 03:44, kelvin <kelvin...@yaho o.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_checkin g.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(strip slashes($value) );
$req .= "&$key=$val ue";
}

$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.p aypal.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*******@attgl obal.net
=============== ===
Jul 13 '07 #6
Captain Paralytic wrote:
On 13 Jul, 03:44, kelvin <kelvin...@yaho o.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_checkin g.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(strip slashes($value) );
$req .= "&$key=$val ue";
}

$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.p aypal.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*******@attgl obal.net
=============== ===
Jul 13 '07 #7
On 13 Jul, 12:57, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Captain Paralytic wrote:
On 13 Jul, 03:44, kelvin <kelvin...@yaho o.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_checkin g.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(strip slashes($value) );
$req .= "&$key=$val ue";
}
$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.p aypal.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...@attgl obal.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*******@attgl obal.net
=============== ===
Jul 13 '07 #9
On Jul 13, 4:10 am, "ED" <e...@example.c omwrote:
"kelvin" <kelvin...@yaho o.com.cnwrote in message

news:11******** **************@ m37g2000prh.goo glegroups.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_checkin g.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(strip slashes($value) );
$req .= "&$key=$val ue";
}
$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.p aypal.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("Locatio n: $url");
exit;

cheers,
ED
It works for me.

Thank you a lot,
Kelvin

Jul 14 '07 #10

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

Similar topics

5
11282
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 me to do this? <input type="Submit" value="Update"> Any help would be greatly appreciated TIA
5
12411
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 all would be amazing. <?php # Script 12.7 - login.php // This is the login page for the site. // Include the configuration file for error management and such.
3
1713
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 with image populate.gif? When I click p1 or p2 button, it will post the page to process.asp. 2) When I check the checkbox, I want the image in submit button change from populate.gif to validate.gif. Unfortunately, the code InputForm.p2.src =...
15
6577
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 the buttons. The problem is when I post a form to itself, the Enter key will not submit the form, it only clears the contents of the text box. The only way I can submit is to click the submit button. Here is a simplified version of my code that I...
6
3106
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 should be submitted as if the button is pressed. Is this correct? Does this behaviour vary across browsers? Chris
4
4939
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 what I'd like to have happen :
4
3516
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 click a button on a pop-up window the javascript for that button click does a 'button.form.submit'. On the Server side there is a Button click event for this button, but for some reason it no longer fires. It worked fine before and everything...
5
2343
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 field alert but still submit. I think the problem lies with the form syntax but I tried different variations and still couldn't get it to work properly; the code is here: function formValidator() { var firstname =...
5
2352
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) { for (var i=0; i <form.elements.length; i++) { if (form.elements.type == 'button') { if (!form.elements.clicked) { alert('Complete the 1st line checks!');
0
9586
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10043
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5446
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3956
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.