Jump to content

Submit a form with a radio button choice


GoogleBoss

Recommended Posts

  :D HI  :D

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="payment@mail.com">

    <input name="submit" >

    </form>

 

ALERTPAY

 

    <form action="https://www.alertpay.com">

    <input type="hidden" name="business" value="payment@mail.com">

    <input name="submit" >

    </form>

 

MONEYBOOKERS

 

    <form action="https://www.moneybookers.com">

    <input type="hidden" name="business" value="payment@mail.com">

    <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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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']}");

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.