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
    Sep 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    passing variables through a link

    I have an online form with 2 submit buttons.

    Unfortunately the form can only be submitted to 1 place.

    I need one button to submit to a _self page
    The other to submit to a _blank page.

    The only way I can think of doing this is to have one button as a link instead

    Can I pass posted variables through a link?

    Cheers,

    tim

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    yes, if your form has a method of "get" you can submit as a querystring rather than as posted values. You could then redirect to the appropriate page using asp or php and just pass the whole querystring through to the processing page depending which button was pressed

    One option to consider (depending on your target audience) is the use of javascript, you can set a forms action in the onclick event of the form buttons.. eg

    Code:
    function changeAction(newaction){
    document.formname.action = newaction;
    }
    Code:
    <form action = "" method = "post">
    <input type = "submit" name = "action1" value = "Button 1" onclick="changeAction('action1.php')">
    <input type = "submit" name = "action2" value = "Button 2" onclick="changeAction('action2.php')">
    </form>

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Not to keen on javascript. Can it be done with PHP

  • #4
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,174
    Thanks
    19
    Thanked 66 Times in 65 Posts
    not client side.
    You would have to reload the page to do it with php. You could post everything through the querystring then redirect to the relevant processing page... eg

    PHP Code:
    if(isset($_POST['button1']){
    header("location: page1.php?{$_SERVER['QUERY_STRING']}")
    }
    else{
    header("location: page2.php?{$_SERVER['QUERY_STRING']}")



  •  

    Posting Permissions

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