Page 1 of 1
help...
Posted: Sat Oct 11, 2003 3:18 am
by elitefreke
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.
Posted: Sat Oct 11, 2003 4:21 am
by volka
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>
Posted: Sat Oct 11, 2003 7:00 am
by mathewvp
if you want to check before submitting the form whether user has entered all the required fields,you should use Javascript
Posted: Mon Oct 13, 2003 3:18 am
by twigletmac
mathewvp wrote:if you want to check before submitting the form whether user has entered all the required fields,you should use Javascript
But you should also check server-side (i.e. with PHP) in case the person has turned off JavaScript or doesn't have it available to them.
Mac