在 PHP 中获取提交按钮值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16334028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get submit button value in PHP
提问by soundsticks
I would like to test my button can get the current value from the date's textbox? I got the value of submit button but I couldn't find any code get name of the button. So what should I call I'm able to view the value?
我想测试我的按钮是否可以从日期的文本框中获取当前值?我得到了提交按钮的值,但找不到任何获取按钮名称的代码。那么我应该怎么称呼我能够查看该值?
$form_button_layout = '<button class="btn" name="oprf" value="view-log" type="submit">View</button>';
<form class="well form-inline" method="post"<?= $form_action_override; ?>>
回答by LovinItAll
If you'd like to get the value of 'oprf' above, then:
如果您想获得上面 'oprf' 的值,则:
$value = $_POST['obrf'];
Should do it in php.
应该在php中做。
回答by Roger
You can try this one
你可以试试这个
if(isset($_POST['oprf'])) {
echo $_POST['oprf'];
}
Hope this helps
希望这可以帮助
回答by mohamed abdallah
Add type property with submit type="submit"
to button tag this will submit the form then receive the form inputs value in php script with super global variable $_POST['input name']
or $_GET[]
wdepends on from action property value by default GET.
添加带有提交type="submit"
到按钮标签的type 属性,这将提交表单,然后在 php 脚本中使用超级全局变量$_POST['input name']
或$_GET[]
wdepends接收表单输入值,默认情况下来自 action 属性值 GET。
回答by Yoko Ishioka
You can do:
你可以做:
if ($_POST['oprf'] == '' || $_POST['oprf'] == NULL) {
//this checks to see if there has been a value that was sent with the
//form
}
I usually use isset for cookies.
我通常将isset用于cookie。
回答by Rijk
I don't think this works consitently in all browsers. Better to work with a customized name
attribute.
我不认为这在所有浏览器中都有效。最好使用自定义name
属性。