Validating and sticky'ing an array

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wickings
Forum Newbie
Posts: 5
Joined: Tue Sep 28, 2010 11:29 am

Validating and sticky'ing an array

Post 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 :)
robnet
Forum Commoner
Posts: 85
Joined: Mon Aug 10, 2009 8:32 am
Location: South East, UK

Re: Validating and sticky'ing an array

Post 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
Post Reply