validating a date - how?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Handler
Forum Newbie
Posts: 9
Joined: Wed Oct 13, 2004 9:02 pm
Location: Albany, NY USA
Contact:

validating a date - how?

Post by Handler »

feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


This has been a challenge .. it may be simple to you, but I'm leanring.

My index page goes like such :

Code: Select all

<html>
<head>
       <title>Birthday</title>
</head>
<body>
<?php
$m=1;
$y = date("Y");
$yy = $y -99;
$months = array("January","February","March","April","May","June","July","August","September","October","November","December");
?>
<form action="test.php" method="POST">
<table border=4>
<tr>
    <td>
        <select name="bmon">
<?php
        foreach ($months as $month) {
        echo "<option value=" .$m. ">" .$month. "</option>";
        $m++;
        }
?>
        </select>
    </td>
    <td>
        <select name="bday">
<?php
        for($d = 1;$d <= 31;$d++) {
        echo "<option value=" .$d.">".$d."</option>";
        }
?>
        </select>
    </td>
    <td>
        <select name="byear">
<?php
        while ($yy <= $y) {
        echo "<option value=" .$y.">".$y."</option>";
        $y--;
        }
?>
        </select>
    </td>
</tr>
<tr>
    <td colspan=3 align="center">
        <input type="submit" value="submit">
    </td>
</tr>
</table>
</form>
</body>
</html>
When I submit I get sent over to my test.php page which looks like this:

Code: Select all

<?php
if (checkdate( $bmon, $bday, $byear) ) {
        header("Location: passed.php");
	} else {
           	 header("Location: index.php");
           }
?>
Here's my problem.:
1) If it does fail how can I tell the user that it failed?
2) When I do put a valid date in it just goes back to the index page instead of passed.php
3) Once I get this to work .. I'll make sure that you can put a date in more current then the current date.

I know checkdate is working .. because if I use var_dump with it I get bool(true or false) pending on the date.

I looked over the tuts .. didn't really see anything that suits what I'm trying to do. Or am I going about this all wrong?

So .. kindly walk me through this! I'm saving all this stuff so I can be embarrassed on how stupid I was in my learning days!

Thanks again!

Handler


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

instead of redirecting to the index page, you could include it, and set an internal variable that you can check for the existance of in the index script.

[php_man]isset()[/php_man]
Handler
Forum Newbie
Posts: 9
Joined: Wed Oct 13, 2004 9:02 pm
Location: Albany, NY USA
Contact:

Post by Handler »

Truthfully .. I saw that function in alot of examples. I could see where it would work for text boxs, radio buttons and check boxs. But how could it work for a pulldown? Because isn't it right off the back something selected with the page loads until the submit button is hit. I think I'm missing something here.

I'ma google around for a little bit .. see what I dig up!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

&lt;?php

if(!checkdate(....))
{
  $error = 'You must clickie the thingy'; // very technical.
  include( 'somepage.php' );
}

?&gt;

Code: Select all

&lt;?php

if(!isset($error)) $error = '';

echo &lt;&lt;&lt;STOP
this is an index page example.&lt;br /&gt;
$error
STOP;

?&gt;
Post Reply