Page 1 of 1

Validating and sticky'ing an array

Posted: Wed Sep 29, 2010 6:33 am
by Wickings
Hey guys! Basic php problem here, hope you are up for it!

I have a form with an array from which users can select date of birth. I am trying to validate the selection when they press submit, and also make their selections sticky.

I have tried my way around the different codes, and my latest attempt looks like this:
<?php

$year = 1960;
while ($year <= 2010) { $year ++;
echo "<option value=\"$value\"" }
//making the selection sticky
if(isset($_POST['year'])) && ($_POST['year'] == $year)){
echo "selected=\"selected\"";
//end sticky
}
echo ">$value</option>n";

}
?>
As far as i know i could be close, but i guess i could also be way of. Hope you guys will take some time to help me :)

Re: Validating and sticky'ing an array

Posted: Wed Sep 29, 2010 9:09 am
by robnet
You're pretty close with the theory. Your code is just currently a bit buggy.

Checkout the fundamentals post and look into turning on error reporting. This is invaluable for catching those simple typos that we all make: viewtopic.php?f=1&t=21400

It's probably also worth checking the html syntax for html select entities: http://www.w3schools.com/tags/tag_select.asp