[英]Form data and Button in the same _POST
晚间!
我遇到了一个问题,弄清楚如何使代码的特定部分正常工作,我有以下几点:
<form>
TestCheckBox
<input type="checkbox" name="TestCheckBox" value="Yes" />
</form>
<div id="search">
<input type="text" id="search_bar" />
<input type="button" value="Search!" />
</div>
在一个php文件中,我有这个:
if($_POST['TestCheckBox'] == 'Yes'){
echo "TEST";
}
if (isset($_POST['action']) && !empty($_POST['action'])) {
generateHTML($_POST['action']);
}
else {
echo "NOTHING IS HERE";
}
显然,这不是该怎么做。 我很好奇我可以让搜索栏提交也包含在复选框中的帖子数据。
(用于搜索栏,并且复选框是高级搜索选项,因此自然而然我只想要一个搜索按钮)。
谢谢!
包括标签(告知用户使用什么控件并提供较大的点击目标(对于复选框和单选按钮尤为重要)),这也是有益的。
这样:
<form method="post">
<label for="TestCheckBox">TestCheckBox</label>
<input type="checkbox" name="TestCheckBox" id="TestCheckBox" value="Yes" />
<div id="search">
<label for="search_bar">Query</label>
<input type="text" id="search_bar" name='action' />
<input type="submit" value="Search!" />
</div>
</form>
您必须将<form>
包裹在所有<inputs>
周围。
<form>
TestCheckBox
<input type="checkbox" name="TestCheckBox" value="Yes" />
<div id="search">
<input type="text" id="search_bar" />
<input type="button" value="Search!" />
</div>
</form>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.