如何获取提交类型按钮的id,按下按钮时(PHP + HTML) [英] How to get id of submit type button, when button is pressed (PHP + HTML)
问题描述
我想打印出我按下的按钮的ID。该ID是为表格中的每个按钮动态设置的。这是我的HTML代码:
I want to print out the id of the button I pressed. The id is set dynamically for each button in a table. This is my HTML code:
echo '<td><center><input type="submit" id="'.$row['I_ID'].'" class="btn"
name="Add" value ="Add to cart"><center></td><tr>';
我想在这里打印按钮的ID。有建议?如果(isset($ _ POST ['Add'])){
And I want to print the id of the button here. An suggestions? Thanks.
if (isset($_POST['Add'])) {
$ID = $_GET['id'];
echo $ID;
echo '<br/>' . "* The item has been added to your cart.";
}
推荐答案
如果您不希望使用隐藏字段,您可以像这样设置提交按钮:
If you do not wish to use a hidden field, you could set your submit button like this:
<button type="submit" name="id" value="value">Submit</button>
然后你可以用 $ _ GET ['id']
。
Then you can catch it with $_GET['id']
.
您可以使用许多按钮( type =submit
) id
),并且该值将是被点击的值,或者是第一个,如果通过按回车提交表单。
You can have many buttons of type="submit"
with the same name (id
), and the value will be the one which was clicked, or the first one, if the form was submitted by pressing enter.
这篇关于如何获取提交类型按钮的id,按下按钮时(PHP + HTML)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!