Reputation: 1
I am building an ecommerce web application for School Education. The customers have a choice between three payment methods. Let's Say Paypal, Moneybookers (Skrill) and Alertpay. That means: each product must have three "Buy Now" Buttons. Here are examples of these buttons:
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 they will have to choose one payment method by selecting it with the radio button.
After their selection, they will submit their choice by clicking on a button and according to their choice, 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
Upvotes: 0
Views: 298
Reputation: 347
Assign each form an Id. For example
<form id="paypal" action="https://www.paypal.com">
<input type="hidden" name="business" value="[email protected]">
<input name="submit" >
</form>
Then set the radios value to Form Id. For example
<input type="radio" name="payMethod" value="paypal" class="paymentMethod" /> PayPal<br />
<input type="radio" name="payMethod" value="aleartPay" class="paymentMethod" /> Alert Pay<br />
<input type="radio" name="payMethod" value="moneyBookers" class="paymentMethod" /> Money Brookers<br />
Then do following on button click
var selectedMethodId = $(".paymentMethod:checked").val();
$('#'+selectedMethodId).submit();
Upvotes: 1
Reputation: 109180
If you want one page where the selected radio button changes the action
of the <form>
then you're either going to need to:
Submit the page to the server on selection of a radio button. The returned form has the required action
value.
Use some JavaScript to set the action
attribute when a radio button is select. This avoids waiting on a new page to load.
But the latter method does require a little code to handle the radio button selection event, and you need to consider if you want to support users who have disabled JavaScript.
Upvotes: 0