Jump to content

Date selection form


sted999

Recommended Posts

Hiya all.

 

I am trying to create a date selection form using PHP. Selecting the day and the month work just fine, but when i enter the code for the year I just get the white page which suggests to me that my code for selecting a year is wrong. Ive been fiddling with it for hours, can anybody see where I am going wrong? Also does anyone know how to add validation to the form e.g. can only select 1-28 if Feb is selected, or is this best done when the form is processed?

 

Thanks,

stephen.

 

echo "<form action='' method='post'>\n";

 

$todayMO = date("n",$today);

echo "<select name='dateMO'>\n";

for ($n = 1;$n <= 12;$n++)

{

echo "<option value = $n\n";

if ($todayMO == $n)

echo " selected";

echo "> {$monthName[$n]}\n";

}

echo "</select>";

 

 

$todayDay = date("d",$today);

echo "<select name='dateDay'>\n";

for ($n = 1;$n <= 31;$n++)

{

echo " <option value=$n";

if ($todayDay == $n )

echo " selected";

echo "> $n\n";

}

echo "</select>\n";

 

//The troublesum code

$startYr = date("Y", $today);

echo "<select name='dateYr'>\n";

for ($n=$startYr;$n <= $startYr + 3;n++)

{

echo " <option value=$n";

if ($startYr == $n )

{

echo " selected";

}

echo "> $n\n";

}

echo "</select>\n";

 

echo "</form>\n";

 

?>

Link to comment
https://forums.phpfreaks.com/topic/152213-date-selection-form/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.