HTML5 发展如火如荼,随着各大浏览器对 HTML5 技术支持的不断完善以及 HTML5 技术的不断成熟,未来 HTML5 必将改变我们创建 Web 应用程序的方式。今天这篇文章向大家推荐10款优秀的HTML5开发工具,帮助你更高效的编写…
March 25, 2016
同一表单内设置两个或两个以上的提交按钮 Two submit buttons in one form
给相同 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 }
本文: 同一表单内设置两个或两个以上的提交按钮 Two submit buttons in one form