View Full Version : Redirect based on Radio Buttons selected

08-13-2012, 02:43 PM

I think this is a PHP question, but it might not be. I have a design that I am coding up for a friend, however I am currently stuck on a page.

I need to code the form design, shown below, to send a user to a different paypal URL depending on the choice they make on the form.

(The current way they do it is found here: http://spaandmassage.co.uk/gift_vouchers.html


Any help would be great.

08-13-2012, 03:08 PM
First use this HTML form and give the radiobuttons the same name like I just did package.

<form action="action.php" method="POST">
<input name="package" type="radio" value="30">
<input name="package" type="radio" value="60">
<input name="package" type="radio" value="90">
<input name="package" type="radio" value="120">

Now in action.php, it will use a case switch to check the value from the HTML form and do actions accordingly

switch ($_POST['package'])
case 30:
echo "30 min link here";
case 60:
echo "60 min link here";
case 90:
echo "120 min link here";
case 120:
echo "120 min link here";
echo "Please pick an option";

You can use the PHP function header() to redirect the user to your link like this.

header("Location: http://paypal-link-goes-here.html");

Cyb :)

08-13-2012, 03:10 PM
As they must all be submitted as forms, you'll have to create all the forms like you have already, store the IDs of all those forms as an select value for each option



<option value = "form1" >Submit form 1</option>


Then use Javascript or jQuery to submit that form when the select is changed, button is clicked or what ever else you'd like to fire the event.

08-14-2012, 11:37 AM
Hi guys,

thanks for the replies, but I looked into it a bit further and it is actually more complicated. I have no idea how to convert the current code they use for paypal into radio buttons.

The current code used for a single button, looks like this.

<form action="https://www.paypal.com/cgi-bin/webscr" method="post" class="align">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="7NLN7KAJY7U36">
<input type="image" src="img/buynow.png" border="0" name="submit" alt="PayPal - The safer, easier way to pay online.">
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1">

I have to somehow put this and 3 similar bits of code into radio buttons. The only thing that changes is the
value="7NLN7KAJY7U36" bit.

In my first post there is the URL for the original page if that helps. I am really stuck here. If anyone can work this out, I'd be most grateful!