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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.