Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form not using dates passed. Need PHP, HTML expert 2

Status
Not open for further replies.

RPGguy

Programmer
Jul 27, 2001
73
US
I'm calling a script from my main menu without passing from and to date. The script will use today(from) + 30 days(to) if no date passed. This works fine, here is the code:
<?
$today = Date(&quot;Y-m-d&quot;);
$from = $_REQUEST[&quot;fromd&quot;];
$thru = $_REQUEST[&quot;thrud&quot;];
if ($from < $today)
{
$from = $today;
}

if ($from >= $thru)
{
$thru = date(&quot;Y-m-d&quot;,strtotime($from) + (30 * 24 * 60 * 60));
}
?>

On the screen the user can change both from and to dates. They must then click the 'refresh' button which calls the same html and should pass the new dates selected as the parms:
<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; width=&quot;750&quot; id=&quot;AutoNumber4&quot; height=&quot;1&quot;>
<tr>
<td width=&quot;446&quot;>

<p align=&quot;right&quot;><i><font size=&quot;5&quot;>Scheduled Service from </font></i>

<INPUT name=from readOnly style=&quot;border:1px solid #FFFFFF; TEXT-ALIGN: right; color:#3399FF; font-size:10pt; font-weight:bold&quot; value=&quot;<? print $from; ?>&quot; size=&quot;8&quot; tabindex=&quot;1&quot;><INPUT onclick=&quot;fPopCalendar(from,from); return false&quot; type=button id=button1 name=button1 value=&quot; ? &quot; style=&quot;font-size: 8pt&quot; ></td>


<td width=&quot;207&quot; height=&quot;1&quot;>

 <i><font size=&quot;5&quot;>thru </font></i>

<INPUT name=thru readOnly style=&quot;border:1px solid #FFFFFF; TEXT-ALIGN: left; font-size:10pt; color:#3399FF; font-weight:bold&quot; value=&quot;<? print $thru; ?>&quot; size=&quot;8&quot; tabindex=&quot;2&quot;>
<INPUT onclick=&quot;fPopCalendar(thru,thru); return false&quot; type=button id=button2 name=button2 value=&quot; ? &quot; style=&quot;font-size: 8pt&quot; ></td>
<form method=POST target=&quot;_top&quot; action=&quot;schedulepage.html?fromd=<? print $from ?>&thrud=<? print $thru ?>&quot;>
<td width=&quot;97&quot;><INPUT type=&quot;submit&quot; value=&quot;Refresh&quot; name=&quot;B1&quot; style=&quot;font-size: 10pt&quot;></td>
</form>
</tr>
</table>

The fPopCalendar works fine. It brings both dates back to the screen in 'from' and thru'. The problem is the submit calls the same script but it doesn't pass the new dates. The url shows:
?fromd=2004-02-15&thrud=2004-03-16

even though I selected 2004-3-31 as the thru date and it showed on the screen but is not being passed as the parameter. Any ideas why?

Thanks to all for their help.

Scott
 
When I try and 'print' them nothing is displayed.
 
1. you have POST method:
form method=POST target=&quot;_top&quot;

2. action=&quot;schedulepage.html?fromd=<? print $from ?>&thrud=<? print $thru ?>

$fromd and $thrud are known by the server (php) with the original value, not the value entered by user because user still not send it to server, so $fromd and $thrud will have the original value.

3. after user press refresh or submit, you send the data in *POST* not *get*.

Cheers.
 
Still not refreshing with the new date range!? I put both input fields in the form (thanks sleipnir214) and changed the 'post' to a 'get'. Maybe I misunderstood what your answer was. I'm still confused because the URL on the screen shows the from and to dates with my new dates but they're not being used. I would think that if the URL has the right parms the program should retrieve them like any other script. The print statements in the code below never change from the original values even though they do on the URL.

<table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;border-collapse: collapse&quot; bordercolor=&quot;#111111&quot; width=&quot;750&quot; id=&quot;AutoNumber4&quot; height=&quot;1&quot;>
<tr>
<td width=&quot;750&quot;>
<? print $from; ?>
<? print $thru; ?>
<form method=&quot;GET&quot; target=&quot;_top&quot; action=&quot;schedulepage.html?from=<? print $from ?>&thru=<? print $thru ?>&quot;>

<p align=&quot;center&quot;><i><font size=&quot;5&quot;>Scheduled Service from</font></i>
<INPUT name=from readOnly style=&quot;border:1px solid #FFFFFF; TEXT-ALIGN: right; color:#3399FF; font-size:10pt&quot; value=&quot;<? print $from; ?>&quot; size=&quot;8&quot; tabindex=&quot;1&quot;>
<INPUT onclick=&quot;fPopCalendar(from,from); return false&quot; type=button id=button1 name=button1 value=&quot; ? &quot; style=&quot;font-size: 8pt&quot; > <i><font size=&quot;5&quot;>thru </font></i>

<INPUT name=thru readOnly style=&quot;border:1px solid #FFFFFF; TEXT-ALIGN: left; font-size:10pt; color:#3399FF&quot; value=&quot;<? print $thru; ?>&quot; size=&quot;8&quot; tabindex=&quot;2&quot;>
<INPUT onclick=&quot;fPopCalendar(thru,thru); return false&quot; type=button id=button2 name=button2 value=&quot; ? &quot; style=&quot;font-size: 8pt&quot; >       <INPUT type=&quot;submit&quot; value=&quot;Refresh&quot; name=&quot;B1&quot; style=&quot;font-size: 10pt&quot;></p>
</td>
</form>
</tr>
</table>

Would anyone recommend this be done an entirely different way or is the theory good?
 
It comes back:
'Array ( )' which obviously isn't good. I guess I'm not understanding the whole timing of when fields are populated, scripts are executed, etc...
 
When data is submitted, the arrays $_GET, $_POST, $_COOKIE, etc, are populated before your PHP script ever runs. That data is part of the request data sent from the browser.

Minimize your problem. Get all that damned JavaScript stuff out of your form and enter a date by hand -- I can't tell where the problem is with so many things going on.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
To say anything about where this goes wrong I'd need to see the script running. Like Sleipnir says $_GET etc. are populated before your script is run, so it seems the actual submission of the variables goes wrong but I can not figure that wout without seeing the script running.
 
I insist:

<form method=&quot;GET&quot; target=&quot;_top&quot; action=&quot;schedulepage.html?from=<? print $from ?>&thru=<? print $thru ?>&quot;>

$from and $thru are values know by PHP with the original ones, so when you hit &quot;refresh&quot; buttom (your <INPUT type=&quot;submit&quot; value=&quot;Refresh&quot; name=&quot;B1&quot; style=&quot;font-size: 10pt&quot;>) you are passing the values you entered **BUT** the **action** is overriding the values!!! with the original ones!!! let the <form> tag with no pre-values, i mean:


<form method=&quot;GET&quot; target=&quot;_top&quot; action=&quot;schedulepage.html&quot;>

and pass the original values with PHP, not GET..

Cheers.
 
True.

I bet you did print($_GET) and not print_r($_GET). Cause array() is the output you get from print, not from print_r if I'm right
 
There is a difference in the output between print and print_r when applied to an array.
Code:
# print of an array, empty or not produces
Array

# print_r of an empty array produces
Array()
 
Thanks to everyone for helping. I really appreciate it.

I passed the variables in the URL because I thought by using the same form in the action, the script would start over and perform exactly the same way. I wanted the selected dates passed in and used the second time.

When CHACALINC says 'and pass the original values with PHP, not GET' I'm not sure what he (or she) means (sessions variables?). Once the screen comes up the first time I don't care about the original dates. The first time, no variables are passed (it's called from my main menu) and the script then uses today as from and (today + 30) as thru. After that I want the dates selected by the user.

If I called this script with the dates preselected and passed in the URL I think it would work fine.
 
That phrase should have read &quot;and pass the original values with POST, not GET&quot;.

It's not the passing of the values in the URL that bothers me. It's the fact that the &quot;action&quot; attribute of your form explicitly reference those variables, which it should not.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
I'm a he...

if (!isset($_POST['from']) $from=today() else $from=$_POST['from'];
if (!isset($_POST['thru']) $thru=today()+30 else $thru=$_POST['thru'];

today() function is all yours...

<form name=&quot;a_name&quot; method=&quot;POST&quot; action=&quot;schedulepage.html&quot;>

comprendez vouz?

Cheers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top