multiple buttons on a form

前端 未结 6 800
遥遥无期
遥遥无期 2020-12-06 02:28

I have a clear button that I want to tie into some php coding. how do I detect if the clear button is pressed. When the user press clear, i\'m going to have it update a sql

6条回答
  •  猫巷女王i
    2020-12-06 02:49

    You check the post or get data from your form, using the name of the button:

    PHP (after submission):

    if(isset($_POST['reset'])) { /* ...clear and reset stuff... */ }
    else if(isset($_POST['submit']) { /* ...submit stuff... */ }
    

    Alternatively, you have two buttons with the same name, which both submit your form, and if/else their values:

    PHP (after submission):

    if($_POST['submit']==0)      { /* ...clear and reset stuff... */ }
    else if($_POST['submit']==1) { /* ...submit stuff... */ }
    else if($_POST['submit']==2) { /* ...do something else... */ }
    

提交回复
热议问题