How to redisplay selected value in a list menu on error
Posted: Sun Dec 06, 2009 11:24 am
good day all,
Please i have a form with list menus where students select their course and grades. and then submit them.
may be if an error occours how do i regisplay the the option the user selected in the list menu.
I was able to do this with a static html form, but dont know how to go about it in a dynamic generated form, here is my code that generated the form.
Please how do i redisplay the users selected option in case the user selected more that one subject at a time can anybody give me a clue?
Thanks alot in advance
Please i have a form with list menus where students select their course and grades. and then submit them.
may be if an error occours how do i regisplay the the option the user selected in the list menu.
I was able to do this with a static html form, but dont know how to go about it in a dynamic generated form, here is my code that generated the form.
Code: Select all
<?php
// this is the array for the subject select menu items.//
$ssce = array("Subject" => "",
"Elective Mathematics" => "mathematics",
"Core Mathematics" => "core-maths",
"English" => "english",
"Physics" => "physics",
"Chemistry" => "chemistry",
"Biology" => "biology",
"Geography" => "geo",
"Intergrated Science" => "int-sci",
"Social Studies"=> "social",);
// here is the grade for the grade select item menu//
$grades = array("A1", "B2", "B3", "C4", "C5", "C6", "D7", "E8", "F9",);
// here is the function that i call to construct the form
function subjects($ssce)
{
echo "<li><select name=\"subject[]\">\n";
foreach($ssce as $option => $value)
{
echo "<option value=\"".$value."\">\n".$option."</option>\n";
}
echo "</select>\n";
}
// here is the function for the grade select menu items//
function grades1($grades)
{
echo "<select name=\"grade[]\">\n";
// echo'<option value="">grade</option>';
foreach($grades as $grade)
{
echo "<option value=\"".$grade."\">\n".$grade."</option>\n";
}
echo "</select>\n</li>";
}
/// here is the last part of the code where i output the form//
echo'<form name="subjects" method="POST" action="'.$_SERVER['PHP_SELF'].'"><ol>';
for($a=1; $a<=5; $a++)
{
subjects($ssce); grades1($grades);
}
echo'</ol>';
echo'<input type="submit" name="submit" value="Register" />';
?>
Thanks alot in advance