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

 

 

 

 

 

 

 

 

 

 

 

 

 

 

You should have a page title in an h1 element with an id of title You should have a short explanation in a p element with an id of description You should have a form element with an id of survey-form Inside the form element, you are required to enter your name in an input field that has an id of name and a type of text Inside the form element, you are required to enter your email in an input field that has an id of email If you enter an email that is not formatted correctly, you will see an HTML5 validation error Inside the form, you can enter a number in an input field that has an id of number The number input should not accept non-numbers, either by preventing you from typing them or by showing an HTML5 validation error (depending on your browser). If you enter numbers outside the range of the number input, which are defined by the min and max attributes, you will see an HTML5 validation error For the name, email, and number input fields, you can see corresponding label elements in the form, that describe the purpose of each field with the following ids: id="name-label", id="email-label", and id="number-label" For the name, email, and number input fields, you can see placeholder text that gives a description or instructions for each field Inside the form element, you should have a select dropdown element with an id of dropdown and at least two options to choose from Inside the form element, you can select an option from a group of at least two radio buttons that are grouped using the name attribute Inside the form element, you can select several fields from a series of checkboxes, each of which must have a value attribute Inside the form element, you are presented with a textarea for additional comments Inside the form element, you are presented with a button with id of submit to submit all the inputs Fulfill the user stories and pass all the tests below to complete this project. Give it your own personal style. Happy Coding!
10-03
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值