Mar*_*ams 4 php forms post json
我有一个php表单(要遵循的代码),其提交按钮JSON-events.php
以action
(method = POST
)运行.在JSON事件代码中,我正在测试表单是否已使用提交if (!empty($_POST))
.我的问题是JSON事件代码似乎没有识别$_POST
.
下面是表单侧代码部分.
<div class="simple_overlay" id="searchform">
<form id="myform" class = "cols" action="json-events.php" method="post" >
<h3>Search</h3>
<p>
<label>address/postcode *</label>
<input type="address" id="searchaddress" />
</p>
<p>
<label for="amount">maximum distance:</label>
<input type="text" id="amount" value="5 miles" style=" border:0; color:#43a8c4; font-weight:bold;" />
</p>
<div id="slider-range-min" style="width:130px; margin-left:4px; margin-bottom:20px"></div>
<p id="terms">
<label>Category 1</label>
<input name="cat1" type="checkbox" value="1" checked="checked"/>
</p>
<p id="terms">
<label>Category 2</label>
<input name="cat2" type="checkbox" value="1" checked="checked"/>
</p>
<p id="terms">
<label>Category 3</label>
<input name="cat3" type="checkbox" value="1" checked="checked"/>
</p>
<p id="terms">
<label>Category 4</label>
<input name="cat4" type="checkbox" value="1" checked="checked"/>
</p>
<p id="terms">
<label>Category 5</label>
<input name="cat5" type="checkbox" value="1" checked="checked"/>
</p>
<p id="terms">
<label>Category 6</label>
<input name="cat6" type="checkbox" value="1" checked="checked"/>
</p>
<p id="terms">
<label>Category 7</label>
<input name="cat7" type="checkbox" value="1" checked="checked"/>
</p>
<p id="terms">
<label>Category 8</label>
<input name="cat8" type="checkbox" value="1" checked="checked"/>
</p>
<p id="terms">
<label>Category 9</label>
<input name="cat9" type="checkbox" value="1" checked="checked"/>
</p>
<p id="terms">
<label>Category 10</label>
<input name="cat10" type="checkbox" value="1" checked="checked"/>
</p>
<p>
<input type="hidden" name="searchlat" id="searchlat"/>
</p>
<p>
<input type="hidden" name="searchlong" id="searchlong" />
</p>
<input type="submit" name="search" id="search"/>
<input type="button" value="Check Address" onclick="codeAddressSearch()"/>
<button type="reset">Reset</button>
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
这是JSON的顶部...
if (!empty($_POST)) {
Run Code Online (Sandbox Code Playgroud)
任何帮助非常感谢
empty()
如果$_POST
没有任何值(空数组),将会工作,但在你提交没有任何值的情况下,你仍然得到一个像下面的数组,它不是空的:
Array ( [searchlat] => [searchlong] => [search] => Submit Query )
empty()
只有在$_POST
返回时才会返回true
Array (
)
Run Code Online (Sandbox Code Playgroud)
但它不会发生,因为每个表单都会有一个Sumbit按钮.
只是用
if($_POST) {
//php code
}
Run Code Online (Sandbox Code Playgroud)
它会解决你的问题.
访问http://php.net/manual/en/function.empty.php,了解有关empty()的更多信息
不使用
if (!empty($_POST)) {
Run Code Online (Sandbox Code Playgroud)
检查是否有帖子使用此:
if( $_SERVER['REQUEST_METHOD'] == 'POST') {
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
27870 次 |
最近记录: |