<form class="form-inline" action="./test.php?id=1">
<li class="nav-item">
<div class="form-group">
<select class="custom-select custom-select-lg mb-3" id="objectType">
<option selected>Object Type</option>
<option value="Toy">Toy</option>
<option value="Furniture">Furniture</option>
<option value="Gift">Gift</option>
<option value="Household">Household</option>
<option value="Instrument">Instrument</option>
</select>
</div>
</li>
<li class="nav-item">
<div class="form-group">
<select class="custom-select custom-select-lg mb-3" id="materialType">
<option selected>Material Type</option>
<option value="Mud">Mud</option>
<option value="Cloth">Cloth</option>
<option value="Thread">Thread</option>
<option value="Jute">Jute</option>
<option value="Cotton">Cotton</option>
<option value="Can">Can</option>
<option value="Bamboo">Bamboo</option>
</select>
</div>
</li>
<li class="nav-item">
<div class="form-group">
<div class="input-group">
<input class="form-control" type="search" placeholder="Search">
<span class="input-group-btn">
<button class="btn btn-outline-secondary" type="submit" id="searchSubmit"><i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
</li>
</form>
我有这个表格。当调用提交按钮test.php
时,将使用请求ID值1调用页面。在test.php
表单字段中,将使用值进行查询。
部分的test.php代码段
$id=$_REQUEST['id'];
if ($id==1)
{
$result = search($_POST['imageName'],$_POST['objectType'],$_POST['materialType']);
echo $_POST['imageName'];
}
else
{
$result = home_page_image();
}
填写完字段后点击提交按钮时,浏览器地址栏中没有显示test.php?id=1
,确认我没有调用该页面。
修改1
我添加了方法(POST
)作为他答案中提到的@ PL200,但在search()
中test.php
函数后没有回音。我也发出警报但没有显示。 alert是search
函数之前的工作,post值既不是search
函数之前也不是#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include <string>
#include <zlib.h>
#pragma comment(lib, "zdll.lib")
static char LookupDigits[] = {
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,62,0,0,0,63,52,53,54,55,56,57,58,59,60,61,
0,0,0,99,0,0,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,
20,21,22,23,24,25,0,0,0,0,0,0,26,27,28,29,30,31,32,33,34,35,36,
37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
};
int FromBase64Simple(const unsigned char* pSrc, int nLenSrc, unsigned char* pDst, int nLenDst)
{
int nLenOut = 0;
for (int j = 0; j<nLenSrc; j += 4)
{
if (nLenOut > nLenDst)
{
return(0); // error, buffer too small
}
unsigned char s1 = LookupDigits[*pSrc++];
unsigned char s2 = LookupDigits[*pSrc++];
unsigned char s3 = LookupDigits[*pSrc++];
unsigned char s4 = LookupDigits[*pSrc++];
unsigned char d1 = ((s1 & 0x3f) << 2) | ((s2 & 0x30) >> 4);
unsigned char d2 = ((s2 & 0x0f) << 4) | ((s3 & 0x3c) >> 2);
unsigned char d3 = ((s3 & 0x03) << 6) | ((s4 & 0x3f) >> 0);
*pDst++ = d1; nLenOut++;
if (s3 == 99) break; // end padding found
*pDst++ = d2; nLenOut++;
if (s4 == 99) break; // end padding found
*pDst++ = d3; nLenOut++;
}
return(nLenOut);
}
std::string decompress_string(const std::string& str)
{
z_stream zs; // z_stream is zlib's control structure
memset(&zs, 0, sizeof(zs));
inflateInit(&zs);
zs.next_in = (Bytef*)str.data();
zs.avail_in = str.size();
int ret;
char outbuffer[32768];
std::string outstring;
do
{
zs.next_out = reinterpret_cast<Bytef*>(outbuffer);
zs.avail_out = sizeof(outbuffer);
ret = inflate(&zs, 0);
if (outstring.size() < zs.total_out)
{
outstring.append(outbuffer, zs.total_out - outstring.size());
}
}
while (ret == Z_OK);
inflateEnd(&zs);
return outstring;
}
int main()
{
std::string inputData = "eAFjYoAAZiDFCMQgGgQAAJwACg==";
//19 is hardcoded since I know its size prior to this call
std::string res(19, '\0');
FromBase64Simple((unsigned char*)inputData.c_str(), inputData.size(), (unsigned char*)res.data(), res.size());
std::string d = decompress_string(res);
for (int c : d)
{
printf("%02x", c);
}
printf("\n");
getchar();
return 0;
}
函数之后的回显。这表明表单值未在test.php中发布。
编辑2
实际上,当我点击提交按钮时,我会调用同一页面。
答案 0 :(得分:1)
您的表单中没有包含任何方法。将html的第一行更改为:
<form class="form-inline" method="POST" action="./test.php?id=1">
这应该可以解决您遇到的问题。
答案 1 :(得分:1)
我理解你要做的是什么,但请注意,有些浏览器会忽略使用form action属性传递的查询参数。因此,无论何时提交表单,在某些浏览器上都可能未定义$_GET['id']
,只是行为不一致。
另外,您没有为表单指定任何方法属性。
使用隐藏的输入表单元素来传递您的值,这是推荐的方法。
<form class="form-inline" action="./test.php" method="post">
<!-- put values to pass here -->
<input type="hidden" value="1" name="id" />
...
</form>
此外,您还可以将隐藏的输入字段放在表单元素之外,并使用表单ID 通过输入字段表单属性来引用它。见下面的例子:
<form id="form-id" class="form-inline" action="./test.php" method="post">
<!-- put values to pass here -->
...
</form>
<!-- Bind this hidden input field to your form -->
<input type="hidden" value="1" name="id" form="form-id" />
请注意,您可以在单个表单中使用的隐藏输入字段数量没有限制,但是要简单。
答案 2 :(得分:0)
表单输入没有name
。
<form class="form-inline" action="./test.php?id=1" method="POST">
<li class="nav-item">
<div class="form-group">
<select class="custom-select custom-select-lg mb-3" name="objectType">
<option selected>Object Type</option>
<option value="Toy">Toy</option>
<option value="Furniture">Furniture</option>
<option value="Gift">Gift</option>
<option value="Household">Household</option>
<option value="Instrument">Instrument</option>
</select>
</div>
</li>
<li class="nav-item">
<div class="form-group">
<select class="custom-select custom-select-lg mb-3" name="materialType">
<option selected>Material Type</option>
<option value="Mud">Mud</option>
<option value="Cloth">Cloth</option>
<option value="Thread">Thread</option>
<option value="Jute">Jute</option>
<option value="Cotton">Cotton</option>
<option value="Can">Can</option>
<option value="Bamboo">Bamboo</option>
</select>
</div>
</li>
<li class="nav-item">
<div class="form-group">
<div class="input-group">
<input class="form-control" type="search" placeholder="Search" name="imageName">
<span class="input-group-btn">
<button class="btn btn-outline-secondary" type="submit" id="searchSubmit"><i class="fa fa-search"></i>
</button>
</span>
</div>
</div>
</li>
</form>
search()
方法后未显示警告消息,因为在search()
方法中出现问题。我调试并纠正search()
方法中的错误。现在一切正常。