...

View Full Version : Make Form field required



|Lethal Daku|
12-26-2005, 12:53 AM
Hi i have a form here
http://www.oh-twadi.com/forum/msninvite.php
i would like to make the fields required.so if u leave them blank a error pops up and says please fill in the fields

anyone help me out
thanx
heres the form code


<form NAME="mainform" method="post" action="http://www.oh-twadi.com/msnOT/index.php">

<table cellpadding="0" cellspacing="0" border="0" width="100%">


<tr>
<td>Email:</td>
<td><input type="text" name="passport"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="pie" value="Submit" class="button" value="$vbphrase[register]" accesskey="s" /></td>
</tr>


</form>
</tr>

Philip M
12-26-2005, 09:06 AM
<form NAME="mainform" onsubmit="return validForm(this)" method="post" action="http://www.oh-twadi.com/msnOT/index.php">

<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>Email:</td>
<td><input type="text" name="passport"/></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="password" name="password"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="pie" value="Submit" class="button" value="$vbphrase[register]" accesskey="s" /></td>
</tr>
</form>
</tr>

<script language="Javascript" type="text/javascript">

function validForm(mainform) {
if (mainform.passport.value == "") {
alert("You must enter a passport");
mainform.passport.focus();
mainform.passport.select();
return false;
}
if (mainform.password.value == "") {
alert("You must enter a password");
mainform.password.focus();
mainform.password.select();
return false;
}
return true;
}

</script>

Note tht this only checks to see if the fields are blank. Entering anything, even a space, will return true. And of course anyone can go directly to your index page - JavaScript is virtually useless as a password protecting script.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum