noobcoder Posted March 29, 2011 Share Posted March 29, 2011 Hey people, First post but i have visited for a while. I have the following HTML form which basically submits the $_session stored variables to PayPal. Advantage being that the user then doesn't need to re-enter their personal info at paypal. <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_ext-enter"> <input type="hidden" name="redirect_cmd" value="_xclick"> <input type="hidden" name="business" value="myemailaddress@business.com"> <input type="hidden" name="item_name" value="myitem"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<? echo $_SESSION['price']; ?>"> <input type="hidden" name="email" value="<? echo $_SESSION['email']; ?>"> <input type="hidden" name="first_name" value="<? echo $_SESSION['fname']; ?>"> <!--the rest of my fields --> <input type="hidden" name="currency_ code" value="GBP"> <input type="hidden" name="country" value="GB"> <input type="submit" class="buybtn" value=""> </form> Problem is i need to also submit some data to a database when the buy button is clicked and i cant have a form with two actions - therefore i need to change from what i have above to the form action being "paypal.php". That paypal.php script needs to do 2 things: 1) submit some data to my mysql database (that part i can do) and 2) submitting some &_session data to the paypal url (https://www.paypal.com/cgi-bin/webscr) just the same as the HTML form does...and take the user to that url...how do i do this? lol. I have no idea where to start in converting the below portion of the above form into a php code that a) submits to a url and (rather than a database) and b) redirects the user to that same url: <input type="hidden" name="cmd" value="_ext-enter"> <input type="hidden" name="redirect_cmd" value="_xclick"> <input type="hidden" name="business" value="myemailaddress@business.com"> <input type="hidden" name="item_name" value="myitem"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<? echo $_SESSION['price']; ?>"> <input type="hidden" name="email" value="<? echo $_SESSION['email']; ?>"> <input type="hidden" name="first_name" value="<? echo $_SESSION['fname']; ?>"> <!--the rest of my fields --> <input type="hidden" name="currency_ code" value="GBP"> <input type="hidden" name="country" value="GB"> Any help anyone can give me will be massively appreciated! Thanks everyone, Bill. Quote Link to comment https://forums.phpfreaks.com/topic/232087-help-converting-a-form-to-a-php-script-paypal-related/ Share on other sites More sharing options...
RussellReal Posted March 29, 2011 Share Posted March 29, 2011 this will not work in PHP You CAN accept the form on your own server, you CAN forward information to paypal.com via cURL which might be able to FOOL PayPal's security features.. but you CAN'T forward a user to another page with PHP while maintaining and modifying POST and GET variables.. Quote Link to comment https://forums.phpfreaks.com/topic/232087-help-converting-a-form-to-a-php-script-paypal-related/#findComment-1193819 Share on other sites More sharing options...
mattal999 Posted March 29, 2011 Share Posted March 29, 2011 You would need to structure it like so (note: this requires Javascript) - have the other form submit to this page (paypal.php): <?php // This page receives the first call, and so do some database stuff. mysql_query("UPDATE ..."); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> <title>Please wait...</title> </head> <body onload="document.forms[0].submit();"> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_ext-enter"> <input type="hidden" name="redirect_cmd" value="_xclick"> <input type="hidden" name="business" value="myemailaddress@business.com"> <input type="hidden" name="item_name" value="myitem"> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<?php echo $_SESSION['price']; ?>"> <input type="hidden" name="email" value="<?php echo $_SESSION['email']; ?>"> <input type="hidden" name="first_name" value="<?php echo $_SESSION['fname']; ?>"> <!--the rest of my fields --> <input type="hidden" name="currency_ code" value="GBP"> <input type="hidden" name="country" value="GB">> </form> </body> </html> The body onload method will execute the submission of the form automatically, so transition from that blank page should be almost instant. Quote Link to comment https://forums.phpfreaks.com/topic/232087-help-converting-a-form-to-a-php-script-paypal-related/#findComment-1193864 Share on other sites More sharing options...
noobcoder Posted March 29, 2011 Author Share Posted March 29, 2011 Thanks, both of you. In which case, the question changes to: is it possible to submit values to mysql triggered by the press of the submit button - whilst keeping the form and its hidden fields untouched. I suspect the answer is no, because as far as i am aware you can only trigger a php script via form action="" but would like to confirm / know if anyone knows a non-java solution to this. Thanks again! Bill. Quote Link to comment https://forums.phpfreaks.com/topic/232087-help-converting-a-form-to-a-php-script-paypal-related/#findComment-1193898 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.