I noticed that Message-ID: <RRoGb.10873$JD6.5055@lakeread04> from TJ
contained the following:
Dear PHP group,
First question:
I have an input form that upon pressing a button validates the values
entered into this form. I am using the following code recall this form if
there is an error in one of the requested fields:
<form name="form1" method="post" action= "InputForm.php" >
All works fine. However, if there is an error and this form is recalled, all
the fields are blanked out when you are brought back to the form. I'd like
for the form to retain the values that had been entered. How do I do this?
Second question:
For the fields that are in error, I'd like for the titles for the fields to
display an asterisk and change the text to red. Have any of you done this
and if so how do you implement it?
Check this out - it simply checks if the field has been entered or not.
If the form is resubmitted it repopulates the textfields with the $_POST
variables.
<html>
<head>
<title>Check fields</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
..red { color: #FF0000}
-->
</style>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?php
function error($field){
if (!$field && $_POST["Submit"]){
print"<p class=\"red\">* ";
}
else{
print"<p>";
}
}
?>
<form name="form1" method="post" action="">
<?php
error($_POST["textfield"]);
?>
First name <input type="text" name="textfield" value="<?php print
$_POST["textfield"];?>">
</p>
<?php
error($_POST["textfield2"]);
?>
Last name <input type="text" name="textfield2"value="<?php print
$_POST["textfield2"];?>"></p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs
http://www.ckdog.co.uk/rfdmaker/