Hi there!
I want to validate a form to make sure a user writes in a name and last name.
If a user writes in only his last name, the form should show again with an error message beside the last name field, but the name value should still be there.
I don't know how to do this, hehe. I'm just a newbie PHP programmer.
Here's what I have so far:
<html>
<head>
</head>
<body>
<form action="formprueba.php" method="get">
<dl>
<dt>Last Name:</dt>
<dd><input type="text" value="" name="name" />
<?php if((isset($_GET['name'])) && ($_GET['name'] == "")){
echo "Please write a correct name.";
}
?>
</dd>
<dt>Last Name:</dt>
<dd><input type="text" value="" name="lastname" />
<?php if((isset($_GET['lastname'])) && ($_GET['lastname'] == "")){
echo "Please write a correct last name.";
}
?>
</dd>
<br />
<dt>
<input type="submit" value="enviar" />
</dt>
<input type="hidden" name="enviado" value="j"/>
</dl>
</form>
</body>
Also, I'm sure this validation is horrible, if you have a couple of minutes, I'd be really grad if someone can show me a more efficient way to validate (without using third party addons).
Thanks SO.