Link to home
Start Free TrialLog in
Avatar of balasundaram
balasundaram

asked on

PHP and html

I have one problem. I am having two pages. In first page if I leave some mantitoy fields empty and if I click submit. The same first page must be displayed with changing the color(to red) of the names of the manditory fields that are not filled but all other data in other fields must be there. I don't know how to do it. Since I am new to php and using PHP3. Please help me.
Avatar of us111
us111
Flag of Luxembourg image

Try the form.php3 file


<?
function TestField($f)
{
if ($f == "")
      print "<font color='#FF0000'>";
}

$field_list = array("Name", "Firstname");

if ($REQUEST_METHOD == "POST")
{ for($i=0; $i<count($field_list);$i++)
  {     if ($$field_list[$i] == "")
          $err=true;
  }
  if ($err<>true)
     header("Location: confirm.php3");
}
?>

<form action="form.php3" method="post">
<?TestField($Name)?>Name</font>
<input type="text" value="<?print $Name?>" name="Name"><br>
<?TestField($Firstname)?>Firstname</font>
<input type="text" value="<?print $Firstname?>" name="Firstname"><br>
<input type="submit" value="submit" name="submit">
</form>
Avatar of balasundaram
balasundaram

ASKER

hello sir,

  your code works perfectly. but if I refresh the previous values are maintained. How I can overcome this problem?
Sure, when you refresh, you post again your data.
What do you need to do ?
ASKER CERTIFIED SOLUTION
Avatar of lar_aas
lar_aas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial