Reputation: 1938
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>
Upvotes: 0
Views: 387
Reputation: 990
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
Upvotes: 0
Reputation: 17732
Change your if (isset($_GET['from']))
to if (isset($_POST['from']))
You're sending the whole form as POST, so GET will be empty.
Upvotes: 1
Reputation: 91734
You are mixing GET
and POST
. Your form is posted, but in your second if
you are checking isset($_GET['from'])
Upvotes: 3
Reputation: 22340
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.)
Upvotes: 4