Contact Form
Posted: Sun Nov 17, 2013 11:48 pm
this problem has cracked my head for a long time.
well, i want to create a ('form.html') and a ('form.php')
inside form.html it likes that >>>
and inside form.php >>>
and now my question comes... if i submit the form in empty form... it should be display "name is required" just beside the
text box in the form... unfortunately, it does not... it moves away to form.php... any help please? emergency!!!

well, i want to create a ('form.html') and a ('form.php')
inside form.html it likes that >>>
Code: Select all
<!DOCTYPE HTML>
<html>
<head>
<style>
.error {color: #FF0000;}
</style>
</head>
<body>
<p><span class="error">* required field.</span></p>
<form method="post" action="form.php">
Name: <input type="text" name="name" value="<?php echo $name;?>">
<span class="error">* <?php echo $nameErr;?></span>
<br><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>Code: Select all
<?php
$name=$_POST["name"];
if (empty($name))
{$nameErr = "Name is required";}
if (!preg_match("/^[a-zA-Z ]*$/",$name))
{
$nameErr = "Only letters and white space allowed";
}
else
{echo $name;}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
and now my question comes... if i submit the form in empty form... it should be display "name is required" just beside the
text box in the form... unfortunately, it does not... it moves away to form.php... any help please? emergency!!!