简体   繁体   English

隐藏的变量没有在PHP中发送

[英]hidden variables not being sent in php

Here is my code where i am trying to send back the values in the from and to field to the same page. 这是我尝试将from和to字段中的值发送回同一页面的代码。 At the top of the page i have this code: (it always echos 'in else loop', i dont understand what is wrong with this simple thing.) 在页面顶部,我有以下代码:(它总是回显“ in else loop”,我不明白这件简单的事情出了什么问题。)

if ($_POST['ok'])
{
if (isset($_GET['from']))
{
$tmp_fromdate=$_GET['from'];
$tmp_todate=$_GET['to'];
echo "in if loop<br/>";
echo $tmp_fromdate. "   ". $tmp_todate."<br/>";
$from_date=date("Y-m-d", strtotime($tmp_fromdate));
$to_date=date("Y-m-d", strtotime($tmp_todate));
echo $from_date. "   ". $to_date."<br/>";
$fdate=date("F d Y", strtotime($tmp_fromdate));
$tdate=date("F d Y", strtotime($tmptodate));
}
else
{
echo "in else loop<br/>";
$start_date='2010-08-01';
$end_date=date ("Y-m-d");
$sdate=date("F d Y", strtotime($start_date));
$edate=date("F d Y", strtotime($end_date));
}
}


<form id="form1" name="form1" method="post">
<div class="demo">

<label for="from">From</label>
<span id="sprytextfield1">
<input type="text" id="from" name="from" />
<span class="textfieldRequiredMsg">mm/dd/yyyy format only.</span>
</span>

<label for="to">to</label>
<span id="sprytextfield2">
<input type="text" id="to" name="to" />
<span class="textfieldRequiredMsg">mm/dd/yyyy format only.</span>
</span>

<input type="submit" id="ok" name= "ok" value="Change Dates"/>
<input type="hidden" name="from" VALUE="<? echo($from);?>"/>
<input type="hidden" name="to" VALUE="<? echo($to);?>"/>
</div>
</form>

Perhaps the third line, if (isset($_GET['from'])) , should instead say if (isset($_POST['from'])) . 也许第三行if (isset($_GET['from']))应该改为if (isset($_POST['from'])) (The first line suggests that a POST request is expected - it can't be both POST and GET at the same time.) (第一行表明应该有POST请求-不能同时是POST和GET。)

You are mixing GET and POST . 您正在混合GETPOST Your form is posted, but in your second if you are checking isset($_GET['from']) 您的表单已发布,但if要检查isset($_GET['from']) ,则在第二秒

Change your if (isset($_GET['from'])) to if (isset($_POST['from'])) 将您的if (isset($_GET['from']))更改为if (isset($_POST['from']))

You're sending the whole form as POST, so GET will be empty. 您将整个表单发送为POST,因此GET将为空。

which 'from' and 'to' fields do you want values back from, because you have two hidden fields with the same name as the date input fields. 您要从哪个“发件人”和“发件人”字段中取回值,因为您有两个与日期输入字段同名的隐藏字段。 you want different names for those. 您想要不同的名称。 if you are getting a date like 1969, then your input is not a valid date to begin with. 如果您获得的日期是1969年,则您输入的内容不是有效的开始日期。 where is $from and $to coming from in the hidden inputs? 隐藏的输入中$ from和$ to来自哪里? you haven't referred to them in the code snippet 您没有在代码段中引用它们

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM