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 6 of 6
  1. #1
    Regular Coder Bengal313's Avatar
    Join Date
    Jun 2002
    Location
    Metro Detroit
    Posts
    298
    Thanks
    8
    Thanked 0 Times in 0 Posts

    multiple buttons on form

    How can I have a single form that has multiple buttons. And since a form has only 1 action option (url) How do I make each button go to different urls?
    "Knowledge Speaks But Wisdom Listens"

  • #2
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    just add another value to each submitbutton.

    you give all submitbuttons the same name, but a differnt value. Then in the page where the form is posted to, you use a switch on $_POST['submitoption'] or whatever you call the buttons (all the same name !) like
    PHP Code:
    switch ($_POST['submbutton']) {
        case 
    "1":
            
    header("Location: http://".$_SERVER['HTTP_HOST']
                          .
    dirname($_SERVER['PHP_SELF'])
                          .
    "/actionpage1.php");

            break;
        case 
    "2":
            
    header("Location: http://".$_SERVER['HTTP_HOST']
                          .
    dirname($_SERVER['PHP_SELF'])
                          .
    "/actionpage2.php");

            break;
        case 
    "3":
           
    header("Location: http://".$_SERVER['HTTP_HOST']
                          .
    dirname($_SERVER['PHP_SELF'])
                          .
    "/actionpage3.php");
            break;


  • #3
    Regular Coder Bengal313's Avatar
    Join Date
    Jun 2002
    Location
    Metro Detroit
    Posts
    298
    Thanks
    8
    Thanked 0 Times in 0 Posts
    The part you posted with the url location do I put that somewhere in the form where the buttons are or do I put that on the resulting pages? Thanx very much
    "Knowledge Speaks But Wisdom Listens"

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK. Say that (part of) your fotm looks like this
    PHP Code:
    echo("<form name=\"actionform\" action=\"switchpage.php\" method=\"post\">");

    echo(
    "<input type=\"submit\" name=\"submit\" value=\"Home\" />");
    echo(
    "<input type=\"submit\" name=\"submit\" value=\"Delete\" />");
    echo(
    "<input type=\"submit\" name=\"submit\" value=\"Insert\" />");

    echo(
    "</form>"); 
    Then you will have something like this in "switchpage.php"
    PHP Code:
    switch ($_POST['submbutton']) {

        case 
    "home":

            
    header("Location: http://".$_SERVER['HTTP_HOST']

                          .
    dirname($_SERVER['PHP_SELF'])

                          .
    "/home.php");



            break;

        case 
    "delete":

            
    header("Location: http://".$_SERVER['HTTP_HOST']

                          .
    dirname($_SERVER['PHP_SELF'])

                          .
    "/delete.php");



            break;

        case 
    "insert":

           
    header("Location: http://".$_SERVER['HTTP_HOST']

                          .
    dirname($_SERVER['PHP_SELF'])

                          .
    "/insert.php");

            break;


    Last edited by raf; 09-16-2003 at 11:44 AM.

  • #5
    Regular Coder Bengal313's Avatar
    Join Date
    Jun 2002
    Location
    Metro Detroit
    Posts
    298
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thank you very much. This will work fine php 4 right!
    "Knowledge Speaks But Wisdom Listens"

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I suppose. Depending on version and settings, you might need to replace $_SERVER by $HTTP_SERVER_VARS

    But just try it out and see what happens ...


  •  

    Posting Permissions

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