首页 > 其他分享 >同一表单内设置两个或两个以上的提交按钮 Two submit buttons in one form

同一表单内设置两个或两个以上的提交按钮 Two submit buttons in one form

时间:2023-03-27 18:39:45浏览次数:36  
标签:button Two submit else buttons action input POST update


给相同 name就可以了, 类似radio的和checkbox的用法:

You can give each input a different value and keep the same name:

<input type="submit" name="action" value="Submit" />
<input type="submit" name="action" value="Update" />
<input type="submit" name="action" value="Delete" />

 

php接收:

Then in the code check to see which was triggered:

if ($_POST['action'] == 'Submit') {
    //action for submit here
} else if ($_POST['action'] == 'Update') {
    //action for update here
} else if ($_POST['action'] == 'Delete') {
    //action for delete
} else {
    //invalid action!
}

 

The only problem with that is you tie your logic to the text within the input. You could also give each one a unique name and just check the $_POST for the existence of that input:

<input type="submit" name="update_button" value="Update" />
<input type="submit" name="delete_button" value="Delete" />

 

And in the code:

if (isset($_POST['update_button'])) {
    //update action
} else if (isset($_POST['delete_button'])) {
    //delete action
} else {
    //no button pressed
}

 


标签:button,Two,submit,else,buttons,action,input,POST,update
From: https://blog.51cto.com/u_8895844/6152823

相关文章