Two submit buttons in one form

前端 未结 19 2104
不思量自难忘°
不思量自难忘° 2020-11-21 23:23

I have two submit buttons in a form. How do I determine which one was hit serverside?

19条回答
  •  我寻月下人不归
    2020-11-22 00:12

    Define name as array.

    (...) some input fields (...)

    Example server code (PHP):

    if (isset($_POST["submit"])) {
        $sub = $_POST["submit"];
    
        if (isset($sub["save"])) {
            // save something;
        } elseif (isset($sub["delete"])) {
            // delete something
        }
    }
    

    elseif very important, because both will be parsed if not. Enjoy.

提交回复
热议问题