同一表单内设置两个或两个以上的提交按钮 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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值