Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Redirect based on Radio Buttons selected

    Hi,

    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.

  • #2
    Regular Coder
    Join Date
    Jan 2009
    Location
    Norway
    Posts
    118
    Thanks
    8
    Thanked 2 Times in 2 Posts
    First use this HTML form and give the radiobuttons the same name like I just did package.

    Code:
    <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">
    </form>

    Now in action.php, it will use a case switch to check the value from the HTML form and do actions accordingly
    PHP Code:
    switch ($_POST['package'])
    {
    case 
    30:
      echo 
    "30 min link here";
      break;
    case 
    60:
      echo 
    "60 min link here";
      break;
    case 
    90:
      echo 
    "120 min link here";
      break;
    case 
    120:
      echo 
    "120 min link here";
      break;
    default:
      echo 
    "Please pick an option";
    }
    ?> 
    You can use the PHP function header() to redirect the user to your link like this.
    PHP Code:
    header("Location: http://paypal-link-goes-here.html"); 
    Sincerely
    Cyb
    Last edited by CyberPirate; 08-13-2012 at 03:10 PM.

  • #3
    New Coder
    Join Date
    Sep 2011
    Posts
    80
    Thanks
    0
    Thanked 13 Times in 12 Posts
    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

    eg:

    PHP Code:

    <select>

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

    </
    select
    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.

  • #4
    New to the CF scene
    Join Date
    Aug 2012
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

    Code:
    <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">
    </form>
    I have to somehow put this and 3 similar bits of code into radio buttons. The only thing that changes is the
    Code:
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •