tags:

views:

57

answers:

4

Here is my code where i am trying to send back the values in the from and to field to the same page. 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.)

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>
+4  A: 

Perhaps the third line, if (isset($_GET['from'])), should instead say 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.)

Hammerite
ok yes, so that was the mistake. Now how can i get back the values for from and to fields. Now i am getting this: `in if loop 1969-12-31 1969-12-31` The values for from and to, how do i retrieve them?
Scorpion King
Try changing the two instances of `$_GET` on lines 5 and 6 to `$_POST`.
Hammerite
i did. it is checking whether from and to are set or not but not getting the value of the fields.
Scorpion King
It looks like your form contains two fields with the name `"to"`, and two fields with the name `"from"`. This is not a good idea, it might be causing the problem you report.
Hammerite
+3  A: 

You are mixing GET and POST. Your form is posted, but in your second if you are checking isset($_GET['from'])

jeroen
+1  A: 

Change your if (isset($_GET['from'])) to if (isset($_POST['from']))

You're sending the whole form as POST, so GET will be empty.

Ryan Kinal
A: 

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. where is $from and $to coming from in the hidden inputs? you haven't referred to them in the code snippet

jmm