How to capture enter key being pressed on pages containing multiple forms?

后端 未结 4 1030
既然无缘
既然无缘 2021-01-31 20:57

I have inherited a web application where the usual ability to press return in any of the input fields has been disabled for the very good reason that the page contains multiple

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-31 21:07

    I don't think you need jQuery or javascript for this. You can indeed detect which Form a user hits submit on, or even which submit button is hit (in case there are more than one submit button per form).

    Here's the code you would use:

    Then for the form-processing script, you would simply check the name of the submit button, for example:

    if (isset($_POST['action1a'])) ... // PHP syntax
    

    Alternatively, you can use images as submit buttons, then you can use the same name for all the submit buttons and just check their values--you can also do this with normal submit buttons if every button has a unique value attribute.


    Edit: One more method is to combine POST and GET values, i.e.:

提交回复
热议问题