954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

one FORM two actions ????

Hey Hii ....
I am solving this problem from last 2 days....
but unable to find solution.
What i am doing is .....
On click of submit button i want to send email and i am taking client to paypal page to do the payment.....
i. e. i want to send FORM data to two different pages.

document.form.action = 'xyz.com/order/email_order.php';				
document.form.submit();
					
document.form.action = 'https://www.paypal.com/cgi-bin/webscr';
document.form.submit();


Its working fine in Mozilla but not in other browsers.....
Or Is there any other solution??
....i dont want 2 submit button.

sandeep_more97
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

when you hit submitt you can have a variable that gets submitted in like php which will post to the page then in the top make a if statement so that if first option is met do this and so forth i think same concept applies to javascript also

HITMANOF44th
Posting Whiz in Training
283 posts since Apr 2009
Reputation Points: 24
Solved Threads: 33
 

If you would like it to post on server side then you could just use curl. So the following is an example script that will display only the paypal page but still submit the post variables to the second link:

$vars='';
foreach ($_POST AS $key => $val) {
$vars.=$key.'='.$val.'&';
}
$vars=substr($vars,0,-1);
$ch = curl_init();
// set the target url
curl_setopt($ch, CURLOPT_URL,'xyz.com/order/email_order.php');
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox
// howmany parameter to post
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$dresult= curl_exec ($ch);
curl_close ($ch);

//now for paypal
$ch = curl_init();
// set the target url
curl_setopt($ch, CURLOPT_URL,'https://www.paypal.com/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") ); // request as if Firefox
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$vars);
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec ($ch);
curl_close ($ch);
echo $result;

So if you post to a page that has just the above script, the above script will then re-post the data to the 2 links provided.

cwarn23
Occupation: Genius
Team Colleague
3,033 posts since Sep 2007
Reputation Points: 413
Solved Threads: 259
 

or you can do a fopen HTTP POST from the email_order.php

$fp = fsockopen($host, 80);
 
// send headers
fputs($fp, "POST /cgi-bin/webscr HTTP/1.1\r\n");
fputs($fp, "Host: https://www.paypal.com/ \r\n");
fputs($fp, "Referer: www.yourdomain.com \r\n");
fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-length: ". strlen($data) ."\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);

// get the output
$result = ''; 
while(!feof($fp)) {
        $result .= fgets($fp, 128);
    }
 
// close the socket connection:
fclose($fp);


although i'm not sure if paypal security will prevent that.

jakesee
Junior Poster
130 posts since Jul 2008
Reputation Points: 21
Solved Threads: 5
 

... i. e. i want to send FORM data to two different pages.

document.form.action = 'xyz.com/order/email_order.php';				
document.form.submit();
					
document.form.action = 'https://www.paypal.com/cgi-bin/webscr';
document.form.submit();

Its working fine in Mozilla but not in other browsers..... Or Is there any other solution?? ....i dont want 2 submit button.

You should go to PayPal's dev site and see how to do it properly. They have a method by which your site receives the form data, processes it, then sends the user off to PayPal with a transaction reference (actually, your return URL with a reference) and other info. When PayPal finishes processing the payment, it will direct the user back to your site with your reference and its transaction info so you can finish logging the payment in your database and complete the sale.

I did this with a real hokie merchandise sales site some years back; it worked well. It worked even better after I eventually converted to OS Commerce; it was all integrated into the database.

Fest3er
Posting Whiz in Training
242 posts since Aug 2007
Reputation Points: 51
Solved Threads: 35
 

Hey Guys...
Thanx for ur valuable time.....
I solved this Problem....
.
.
.
What i did is....
I redirect the user to page from which i m sending an email.
And from there i send required fields to Paypal.com
Mail sending page doesnt shown any O/P.....There i executed the function to send mail.....and redirected user to Paypal.com with reqired fields.

Thanx Once again....

sandeep_more97
Newbie Poster
3 posts since Apr 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You