sted999 Posted April 2, 2009 Share Posted April 2, 2009 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 More sharing options...
Yesideez Posted April 2, 2009 Share Posted April 2, 2009 Please post any code between CODE tags. Validation: easiest done after the form has been submitted. If you want to do it before the form has been submitted you need to use Javascript. Link to comment https://forums.phpfreaks.com/topic/152213-date-selection-form/#findComment-799311 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.