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

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

Html代码  收藏代码
  1. <input type="submit" name="action" value="Submit" />  
  2. <input type="submit" name="action" value="Update" />  
  3. <input type="submit" name="action" value="Delete" />  

 

php接收:

Then in the code check to see which was triggered:

Php代码  收藏代码
  1. if ($_POST['action'] == 'Submit') {  
  2.     //action for submit here  
  3. else if ($_POST['action'] == 'Update') {  
  4.     //action for update here  
  5. else if ($_POST['action'] == 'Delete') {  
  6.     //action for delete  
  7. else {  
  8.     //invalid action!  
  9. }  

 

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:

Html代码  收藏代码
  1. <input type="submit" name="update_button" value="Update" />  
  2. <input type="submit" name="delete_button" value="Delete" />  

 

And in the code:

Php代码  收藏代码
  1. if (isset($_POST['update_button'])) {  
  2.     //update action  
  3. else if (isset($_POST['delete_button'])) {  
  4.     //delete action  
  5. else {  
  6.     //no button pressed  
  7. }  

 

 

原文/转自: 同一表单内设置两个或两个以上的提交按钮 Two submit buttons in one form

posted on 2016-08-17 10:43  飘渺的悠远  阅读(355)  评论(0)    收藏  举报