Hi,

I've got a working copy on:

http://www.framers.nl/hans/itweb/formvalidation.php

Now .. there are some errors I don't understand..

* When I don't fill in something in the first three fields, but only the last field. The script accepts it. (??)

* I've made a simple function 'generateTextfield' which, well, generates a textfield. I did this 'cause i could avoid dreamweaver and typing a lot.

What it doens't do though is:

* Don't show variables, please check my code, I want to echo in the textfields the variables. <? echo $name ?> where $name is of course the variable given by the function.

Please, if you can help me.

I'm very happy with this code, use it if you like

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
<?
//
// Form validation v1.0
// Framers
// Hans Buis
// hans@framers.nl
// http://www.framers.nl
// 20 november 2000
//
// This code is free for everyone, but I would appreciate it when you would sent me an email.
//

// Why bother making those fiels with dreamweaver
function generateTextfield($name, $bgcolor, $size, $error) {
return "<input type="text" name="$name" style="background-color: $bgcolor[$name];" value="echo $name" size="$size">$error[$name] <br>n" ;
}

// In near future we need to do some real validation ..
function validateUsername($username) {
if((strlen($username)<4) &#0124; &#0124; (strlen($username)>8)) {
return true;
}
if(!ereg('^[a-zA-Z0-9]+$',$username)) {
return true;
}
}

// Start the HTML page here
echo ('<html>');
echo ('<body>');

if ($submit) { // The variables will be checked.. no real validation ...yet!

// TODO: On some weird way, the last (fourth) variable is accepted ?!?!

if (!$first) {$error[first] = "Seems like you've forgotten the first field"; $bgcolor[first] = "#FFCCCC"; }
if (!$last) {$error[last] = "Seems like you've forgotten the second field"; $bgcolor[last] = "#FFCCCC"; }
if (!$third) {$error[third] = "Seems like you've forgotten the third field"; $bgcolor[third] = "#FFCCCC"; }
if (!$fourth) {$error[fourth] = "Seems like you've forgotten the fourth field"; $bgcolor[fourth] = "#FFCCCC"; }

else {

// process form

echo "Thank You!";
echo "<br><br>";
echo "This is where the values will be put into the database";
echo "<br><br>";
echo "NOT ACTIVATED YET!";
echo "<br><br>";

}
}

if (!$submit &#0124; &#0124; $error) {

// Shows a nice list of available errors
if ($error[$i]) {
while (list($var, $value) = each($error)) {
echo "$var = $value<br>n";
}
}

?>
<P>
<form method="post" action="<?php echo $PHP_SELF ?>">

<?
// Generates the textfields
?>
FIELD 1: <? echo generateTextfield(first, $bgcolor, 25, $error) ?>
FIELD 2: <? echo generateTextfield(last, $bgcolor, 25, $error) ?>
FIELD 3: <? echo generateTextfield(third, $bgcolor, 25, $error) ?>
FIELD 4: <? echo generateTextfield(fourth, $bgcolor, 25, $error) ?>

<input type="Submit" name="submit" value="Validate!">
</form>
<?

} // end if

?>

</body>
</html>
[/code]



------------------
---------------------
Hans Buis
Framers
http://www.framers.nl