I would like to find a way to display different pages from a form, based on which button is selected. Unfortunately, it seems that that a form is limited to a single ACTION (as defined in the <form>) - and it appears (to my simple mind, anyway) a bit strange that an action is not associated with a button instead?!

Anyway, I appreciate that one can use a PHP variable for the filename; but how do I then change the value of that variable, before the form is POSTed, based on which button is selected... Failing this approach, any ideas for another neat (simple and elegant) way around the problem would be appreciated.

Thanks
Derek

    Hi Derek,

    no problem. you can use different forms. For example:

    <form action="page1.php" method="post">
    <input type="submit" value="action1">
    </form>

    <form action="page2.php" method="post">
    <input type="submit" value="action2">
    </form>

    <form action="page3.php" method="post">
    <input type="submit" value="action3">
    </form>

    Now you have three different buttons on your page, with three different actions.

    I hope I got your question and the answer helps you,

    Andreas

      This works unless you have other input fields like text boxes or check boxes that need to go with each page. AFAIK, any single input tag can only be associated with one form tag.

        OK, I understood.

        At first I didn't realised it the right way. OK, many different inputs and two or more possible buttons:

        there is a way. Use just one submit button, but take a radio button for every action you would like to use. The form will now be sent to one php script, this script detects the radio button that was chosen and redirects the form-inputs to the action (function) of choice.

          Yes! This would work. It pays to remember the goal and not focus too much on the problem.

            9 years later

            Instead of multiple actions in the form,
            How about two submit buttons within the same form, each with their own name attribute.
            ie: formSubmit and formSave.
            When the form is submitted use an if statement to see which name att is posted and proceed from there:

            if(isset($POST['formSubmit'])){
            / do something /
            } else if(isset($
            POST['formSave'])){
            / do something else /
            }

              Write a Reply...