Hey I have solved a lot of my php problems in the last few days but now I'm stuck again.
Bellow is my simplifed php code for a form that is submitted by my users. The form is displayed and the user fills in his information and hits submit. So far everything ok. But now the user forgets to type in his name but chooses one of the options in the selector pull down. Error checking now kicks in and the form is redisplayed with an error message asking the user to type in his name. But now the selector has reset it self to it's default value. Is there a way in php to fix this problem? in other words redisplay the orignal entered user selection after a redisplay.
<?php
if (!eregi("modules.php", $PHP_SELF)) {
die ("You can't access this file directly...");
}
require_once("mainfile.php");
include("header.php");
$module_name = basename(dirname(FILE));
$form_name_block = "
<form action='modules.php?name=$module_name' method='post'>
Name/Company: <input type='text' name='ContactName' size='30' value ='$ContactName'>";
$form_submit_block = "
<input type='hidden' name='Submit' value='Submitted'>
<br><input type='submit' value='Submit'></form>
";
$form_select_block = "
Best Contacted: <SELECT NAME='Reachable'>
<OPTION VALUE='0' selected >Anytime
<OPTION VALUE='1'>Mornings
<OPTION VALUE='2'>Afternoons
<OPTION VALUE='3'>Evenings
<OPTION VALUE='4'>Weekends
</select> ";
if($Submit != "Submitted") //----------if Submit not hit
{
echo "$form_name_block";
echo "$form_select_block";
echo "$form_submit_block";
}
else
{
//----------------Error Checking
if ($ContactName == "")
{
$name_err = "Sorry dude please enter your name";
$Send = "no";
}
else //-------No errors so send
{
echo "Form Submitted";
}
if ($Send = "no")
{
echo "$name_err";
echo "$form_name_block";
echo "$form_select_block";
echo "$form_submit_block";
}
}
?>