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 5 of 5
  1. #1
    New Coder
    Join Date
    May 2004
    Location
    Earth
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Is this possible?

    I seem to remember reading somewhere that php allows a different action to be executed on a form if you have more than one submit button, and that the action of said form is dictated by which button the user clicks.

    Presumably, I need to have the form action going to another php page where this information is digested in the form of an "IF" script, do I?

    Or is it possible to write an "IF" statement on the same page that sends the user to a different page depending on which button they click?

    So basically, what I want is one button to take someone to one page, and another button to take someone to another page - but both buttons are on the same form. Possible or pipe dream?

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    you can use javascript to change the action of a form onclick , but not via PHP , all you can do with PHP is as you noted ,get the form action page to decide which button was clicked (by giving the submit buttons different names)
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    May 2004
    Location
    Earth
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK thx.

    Didnt really want to have to use JS but if thats the only way, then that's what I'll have to do I guess.

    RR

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    if(isset($Submitted)&&($Submitted=='Add'||$Submitted=='Edit'||$Submitted=='Delete')
    {
      switch($Submitted){
         case 'Add':
            require('somepage1.php');
         break;
         case 'Edit':
            require('somepage2.php');
         break;
         case 'Delete':
            require('somepage3.php');
         break;
      }
      /*Note if your files have a same name only with the difference the being equal to the buttons values you can skip the switcher and simply put:
    require($Submitted.'something.php');*/
      unset($Submitted);
    }
    <form method="post" action="thispage.php" >
      <input type="submit" name="Submitted" Value="Add">
      <input type="submit" name="Submitted" Value="Edit">
      <input type="submit" name="Submitted" Value="Delete">
    </form>

  • #5
    New Coder
    Join Date
    May 2004
    Location
    Earth
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks. You had a closing parantheses missing off line 1 but thats given me something to work on.


  •  

    Posting Permissions

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