HTML form with multiple “actions”

前端 未结 3 1930
渐次进展
渐次进展 2020-11-27 18:16

I\'m setting up a form wherein I need two \"actions\" (two buttons):

1 - \"Submit this form for approval\"
2 - \"Save this application for later\"

How do

3条回答
  •  情歌与酒
    2020-11-27 19:03

    As @AliK mentioned, this can be done easily by looking at the value of the submit buttons.

    When you submit a form, unset variables will evaluate false. If you set both submit buttons to be part of the same form, you can just check and see which button has been set.

    HTML:

    PHP

    if($_POST["save"]) {
      //User hit the save button, handle accordingly
    }
    //You can do an else, but I prefer a separate statement
    if($_POST["approve"]) {
      //User hit the Submit for Approval button, handle accordingly
    }
    

    EDIT


    If you'd rather not change your PHP setup, try this: http://pastebin.com/j0GUF7MV
    This is the JavaScript method @AliK was reffering to.

    Related:

    • 2x submit buttons to action different URL
    • Submit form to another page (which is different from the page used in ACTION)

提交回复
热议问题