I'm working on a custom CMS that i'm writing. It's coming along beautifully by the way.
I ran into something of an issue, however and to be frank, I'm a bit stumped.
I have a form laid out and it's meant to collect personal information from site visitors who choose to fill it out. In this case, it's the birthday section of the form. Here's the code.
<select name="birthD">
<?php
for ($i=1; $i<=31; $i++) # I want to add the string "Day" to the beginning of this, but how?
{
if($i == $_POST['birthD']) { $selected="selected"; } else { $selected = ""; }
echo "<option value='$i' \"$selected\">$i</option>";
}
?>
</select>
<select name="birthY">
<?php
for ($i=date(Y); $i>=1900; $i=$i-1) # I want to add the string "Year" to the beginning of this, but how?
{
if($i == $_POST['birthY']) { $selected="selected"; } else { $selected = ""; }
echo "<option value='$i' \"$selected\">$i</option>";
}
?>
</select>
Basically, this code sets out two drop down boxes that lets the user select the day of their birth and the second drop down is the year. The month section is an array with all 12 months, so putting "Month" at the top of that one was easy.
If the form was submitted and
$_POST['birthM'] == "Month" # month of birth
then the form is not processed and a message at the top of the form is displayed saying the form wasn't completed. The $_POST vars are printed on the form so the user input is not lost as the form is actually quite long.
The same goes for day and year, however, because i'm using a for loop with a counter to create the drop down, the user need not enter this info because it's always at 1 for the day and the current year for the year which gives the two $_POST vars a value by default.
I know I can do this by just making arrays, but that would require an array with 31 elements for the month and over a hundred for the year. That just seems like a waste of time. Is it possible to explode the value of $i into an array ? Arrays I can work with!
[EDIT] ******
I had the brilliant Idea of HAND CODING the "Year" option LOL and that did the trick. I've been staring at code all night long so the genius thought of writing HTML instead of PHP didn't hit me right away. Thanks for your time!