GoogleBoss Posted July 7, 2012 Share Posted July 7, 2012 HI I am building an ecommerce web application for School Education. The customer have choice between three payment methods. Let's Say Paypal, Monebookers(Skrill) and Alerpay. That means : each product must have three " Buy Now " Buttons.Here are exemple of these button : PAYPAL <form action="https://www.paypal.com"> <input type="hidden" name="business" value="[email protected]"> <input name="submit" > </form> ALERTPAY <form action="https://www.alertpay.com"> <input type="hidden" name="business" value="[email protected]"> <input name="submit" > </form> MONEYBOOKERS <form action="https://www.moneybookers.com"> <input type="hidden" name="business" value="[email protected]"> <input name="submit" > </form> My purpose is to just have one "Buy Now" button in front of each product. After clicking that button, the customer is redirected to a page where he will have to choose one payment method by selecting it with the radio button. After his selection, he will submit his choice by click on a button and according to his choise, he will land to paypal or alertpay or moneybookers website. I am a novice in php and I know this is possible, but I don't just know how to do it. Any help would be greatly appreciated Quote Link to comment https://forums.phpfreaks.com/topic/265349-submit-a-form-with-a-radio-button-choice/ Share on other sites More sharing options...
PeoMachine Posted July 7, 2012 Share Posted July 7, 2012 You can do a page with the three options in radio buttons. When you submit this form, you can search for the informations on the database... for example: $sql = "SELECT site FROM payment_method WHERE method = '$_POST['payment_method']'"; $stmt = $database->query($sql); $method = $stmt->fetch(PDO::FETCH_OBJ); header("Location: {$method->site}"); It will redirect you to the correspondent site... Or you can just put the site on the value of the radio button and redirect when the form is submited. Quote Link to comment https://forums.phpfreaks.com/topic/265349-submit-a-form-with-a-radio-button-choice/#findComment-1359903 Share on other sites More sharing options...
GoogleBoss Posted July 7, 2012 Author Share Posted July 7, 2012 thank you PeoMachine I forget to mention that I don't use any Database now. I am trying to use something like javascript or php. I think Javascript would do it faster. Have a nice day PeoMachine. Quote Link to comment https://forums.phpfreaks.com/topic/265349-submit-a-form-with-a-radio-button-choice/#findComment-1359930 Share on other sites More sharing options...
PeoMachine Posted July 12, 2012 Share Posted July 12, 2012 On that case, you can treat the selected radio and redirect, or put the site on the value of the radio. 1) <?php switch($_POST['payment_method']) { case 'paypal': $redirect = 'www.paypal.com'; // the others } header("Location: {$redirect}"); 2) <label><input type="radio" name="payment_method" value="www.paypal.com" /> Paypal </label> // The PHP does that <?php header("Location: {$_POST['payment_method']}"); Quote Link to comment https://forums.phpfreaks.com/topic/265349-submit-a-form-with-a-radio-button-choice/#findComment-1361082 Share on other sites More sharing options...
GoogleBoss Posted July 13, 2012 Author Share Posted July 13, 2012 Hi Guy I have done it: Here is my code on the checkout.php. <SCRIPT type="text/javascript" > function choixprop(form_btnrad) { if (form3.choix[0].checked) { window.document.paypal.submit() }; if (form3.choix[1].checked) { window.document.moneybookers.submit() }; if (form3.choix[2].checked) { window.document.alertpay.submit() }; } </SCRIPT> <FORM NAME="form_btnrad"> <INPUT TYPE="radio" NAME="choix" VALUE="1" checked="checked"> PayPal <INPUT TYPE="radio" NAME="choix" VALUE="2"> Skrill/Moneybookers <INPUT TYPE="radio" NAME="choix" VALUE="3"> AlertPay <input name="Pay" type="button" id="Pay" onClick="choixprop(form_btnrad)" value=" "> </div> </FORM> Now, I am trying to do something else. All the html form of these payments gateway are on the same page checkout.php. I would like to put them on anoher page like payments_data.php and then, call them from the main page checkout.php. Is something like this possible. All my researchs say to use an external javascript file. What can I do? Once again, thank for your help. Quote Link to comment https://forums.phpfreaks.com/topic/265349-submit-a-form-with-a-radio-button-choice/#findComment-1361239 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.