PHP-回显POST变量
我对一些POST变量有一个问题,我看不出有什么问题,所以我希望有人能够发现什么是错误的 这是“简单搜索”表单:PHP-回显POST变量,php,jquery,http-post,forms,Php,Jquery,Http Post,Forms,我对一些POST变量有一个问题,我看不出有什么问题,所以我希望有人能够发现什么是错误的 这是“简单搜索”表单: <div id ="form"> <form enctype="multipart/form-data" method="post" action="testdocs-db.php" name="search" id="search" class="search"> <input type="hidden" name="dosearch" value="t
<div id ="form">
<form enctype="multipart/form-data" method="post" action="testdocs-db.php" name="search" id="search" class="search">
<input type="hidden" name="dosearch" value="true">
<table border=0>
<tr>
<td class="label">File Type:</td>
<td>
<?php doSelectMultiple("filetype", $options_filetype, $filetype, ""); ?>
</td>
</tr>
<tr>
<td class="label">File Name:</td>
<td>
<input id="filename" name="filename" class="text" value="<?php echo($filename); ?>">
</td>
<td> </td>
</tr>
<tr>
<td class="label">File Size:</td>
<td>
<input id="filesize_min" name="filesize_min" class="text" value="<?php echo($filesize_min); ?>"><div id="kb">(kb min)</div>
</td>
<td>
<input id="filesize_max" name="filesize_max" class="text" value="<?php echo($filesize_max); ?>"><div id="kb">(kb max)</div>
</td>
</tr>
<tr>
<td class="label"># Results:</td>
<td>
<input id="numresults" name="numresults" class="text"
<?php
if (strlen($numresults) >= 1)
{
echo ("value=\"$numresults\"");
}
else
{
echo ("value=\"10\"");
}
?> >
</td>
<td> </td>
</tr>
<tr>
<td class="label">Order By:</td>
<td>
<?php doSelect("orderby", 1, $options_orderby, $orderby, ""); ?>
</td>
<td>
<?php doSelect("orderbyad", 1, $options_orderbyAD, $orderbyAD, ""); ?>
</td>
</tr>
<tr>
<td class="label">Output Format:</td>
<td>
<?php doSelect("outputformat", 1, $options_outputformat, $outputformat, ""); ?>
</td>
<td>
<?php doSelect("outputlocation", 1, $options_outputlocation, $outputLocation, ""); ?>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" class="submit" value="Search"></td>
<td> </td>
</tr>
简单搜索变量的执行方式与此类似,只是它们正确地回显:
/* do the search */
$filetype = doPost('filetype', $filetype);
$filename = doPost('filename', $filename);
$filesize_min = doPost('filesize_min', $filesize_min);
$filesize_max = doPost('filesize_max', $filesize_max);
$numresults = doPost('numresults', $numresults);
$outputformat = doPost('outputformat', $outputformat);
$orderby = doPost('orderby', $orderby);
$orderbyAD = doPost('orderbyad', $orderbyAD);
$outputLocation = doPost('outputlocation', $outputLocation);
很抱歉代码太多,我不想错过任何重要的东西
如果有人能发现我做错了什么,我很想知道
谢谢
马丁
更新
doPost方法:
FUNCTION doPost($st, $default)
{
if (isset($_POST[$st]))
return $_POST[$st];
else
return $default;
}
高级搜索可以很好地构建查询,但是表单字段没有响应应该设置为它们的值
在这里可以看到完整的代码(没有大量的JS文件):它可以像下面这样简单:在这个输入中
<input type="hidden" name="hiddenfiletype" id="hiddenfiletype"/>
没有价值。或者可能我是哑巴:)当试图以POST方法的形式计算HTML、JS和PHP之间传递的内容时,请使用这些方法中的一种来测试实际输出与您自己的期望值
var_dump( $_POST );
var_export( $_POST );
print_r($_POST, 1);
第一个通常是最好使用的。当单击高级搜索按钮时,我最终通过使用javascript将表单输入的值复制到隐藏输入来解决它,如下所示:
function copy() {
var filetype=$("#filetype option:selected").val();
$("#hiddenfiletype").val(filetype);
var filename=$("#filename").val();
$("#hiddenfilename").val(filename);
var filesize_min=$("#filesize_min").val();
$("#hiddenfilesize_min").val(filesize_min);
var filesize_max=$("#filesize_max").val();
$("#hiddenfilesize_max").val(filesize_max);
var numresults=$("#numresults").val();
("#hiddennumresults").val(numresults);
var orderby=$("#orderby option:selected").val();
$("#hiddenorderby").val(orderby);
var orderbyad=$("#orderbyad option:selected").val();
$("#hiddenorderbyad").val(orderbyad);
var outputformat=$("#outputformat option:selected").val();
$("#hiddenoutputformat").val(outputformat);
var outputlocation=$("#outputlocation option:selected").val();
$("#hiddenoutputlocation").val(outputlocation);
}
形式如下:
<div class="advancedsearchsubmit"><input type="submit" class="submit" onclick="copy();" value="Advanced Search"/></div>
你能发布doPost()的代码吗?
?到底什么不起作用?高级搜索中没有任何字段被发布/回显?不知道这是否是一个问题,但您缺少:$(document).ready(function(){…you functions here…});不会是这样的。不管该字段是否没有值(或是空的),它仍然会提交。我认为这些字段在从帖子中回显时有错误的值。谢谢,我看到当提交高级搜索时,它是按照array(14){[“advancedsearchsubmit”]=>string(1)“1”[“hiddenfiletype”]=>string(5)“excel”的思路提交的[“hiddenfilename”]=>string(4)“test”[“hiddenfilesize_min”]=>string(3)“123”[“hiddenfilesize_max”]=>string(3)“456”[“hiddennumresults”]=>string(2)“12”…
但我正在将这些POST变量设置为与PHP变量相同的名称,并且它们不会显示出来?如果采用hiddenfiletype(“excel”)的话,doPost()的结果是什么再次使用var_dump(doPost());并将该变量置零,直到找到错误的地方。Echo和var_dump()变量输出到页面上-即使这意味着在调试之前只需制作一个小型应用程序。问题是,在提交高级搜索表单时,我会将这些post值设置为变量,并将这些变量作为文本输入值进行回显。与构建mysql查询时使用的值相同,我认为这很好这只是记住了搜索表单中不起作用的值,我看不出如何修复它:s按照k102之前的建议添加缺少的值属性,如果不起作用,让JQuery抛出一个警报框,或者将值记录到控制台,比如说,filetype,并寻找每个层发送/接收的是w的证据这是意料之中的。调查。谢谢,为每个隐藏的输入添加了value属性,但这并没有解决问题。这是一个好主意。我打印了POST变量,下面是一个小片段:[advancedsearchsubmit]=>1[hiddenfiletype]=>[hiddenfilename]=>123[hiddenfilesize\u min]=>456[hiddenfilesize\u max]=>789[hiddennumresults]=>11
因此变量已设置,我将这些变量设置为与简单搜索相同的变量,因此我不知道为什么值设置不正确:(
function copy() {
var filetype=$("#filetype option:selected").val();
$("#hiddenfiletype").val(filetype);
var filename=$("#filename").val();
$("#hiddenfilename").val(filename);
var filesize_min=$("#filesize_min").val();
$("#hiddenfilesize_min").val(filesize_min);
var filesize_max=$("#filesize_max").val();
$("#hiddenfilesize_max").val(filesize_max);
var numresults=$("#numresults").val();
("#hiddennumresults").val(numresults);
var orderby=$("#orderby option:selected").val();
$("#hiddenorderby").val(orderby);
var orderbyad=$("#orderbyad option:selected").val();
$("#hiddenorderbyad").val(orderbyad);
var outputformat=$("#outputformat option:selected").val();
$("#hiddenoutputformat").val(outputformat);
var outputlocation=$("#outputlocation option:selected").val();
$("#hiddenoutputlocation").val(outputlocation);
}
<div class="advancedsearchsubmit"><input type="submit" class="submit" onclick="copy();" value="Advanced Search"/></div>