help...
Moderator: General Moderators
-
elitefreke
- Forum Newbie
- Posts: 3
- Joined: Wed Sep 10, 2003 2:26 am
help...
I am trying to figure out the code for making a field "required" Basically, I just don't want to get a submission with no info and I cannot seem to grasp the concept of the compare features. Please help.
as simple example:
Code: Select all
<html>
<head>
<title>form test</title>
<style texpe="text/css">
span.error { display: block; color: red; }
</style>
</head>
<body>
<?php
if (!isset($_POST['fieldA']) || strlen($_POST['fieldA'])==0)
echo '<span class="error">fieldA is mandatory</span>';
if (!isset($_POST['fieldB']) || strlen($_POST['fieldB'])==0)
echo '<span class="error">fieldB is mandatory</span>';
if (!isset($_POST['fieldC']) || strlen($_POST['fieldC'])==0)
echo '<span class="error">fieldC is mandatory</span>';
?>
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="fieldA" value="<?php echo @$_POST['fieldA']; ?>"/> :field A<br />
<input type="text" name="fieldB" value="<?php echo @$_POST['fieldB']; ?>"/> :field B<br />
<input type="text" name="fieldC" value="<?php echo @$_POST['fieldC']; ?>"/> :field C<br />
<input type="submit" />
</form>
</body>
</html>- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK