900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > 同一表单内设置两个或两个以上的提交按钮 Two submit buttons in one form

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

时间:2021-06-15 09:49:42

相关推荐

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

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。