...

View Full Version : Mandatory Form Fields



ssskaya
06-06-2003, 08:44 PM
I want to set the fields of my form as mandatory. I am using the following script. But it doesn't work.

How should I edit it?

Thanks.

---


<form
action="http://us.geocities.yahoo.com/forms?login=abc"
method="post">
<input type="hidden" name="address"
value="newsletter@abc.com"><input
type="hidden" name="Subject"
value="Newsletter Subscription"><input
type="hidden" name="next_url"
value="http://www.abc.com/nlconf.html"><input
type="hidden" name="mandatory"
value="name city email agree"><input
type="hidden" name="errorpage"
value="nlformerror.html"><table border="0"
width="510">...

Jason
06-06-2003, 09:00 PM
when doing the submit, you could put the direction based on the field input, if there isn't anything then throw and alert that says the field is missing, so basically check to see if all the values aren't null or empty.


Jason

ssskaya
06-06-2003, 09:14 PM
I have just 4 fields so one alert will do it all.

but my problem is:

even when you submit it totally empty, it goes on to say thank you.

I want it to go to the error page instead.

Garadon
06-06-2003, 09:27 PM
ehhh could u perhaps either.

1. post ur entire code.
2. post the link to ur code.


I assume there must be some java script in the part of code u didn't post since there is none in the posted code

ssskaya
06-06-2003, 09:33 PM
Here it is:

<form
action="http://us.geocities.yahoo.com/forms?login=fiscalstudy"
method="post">
<input type="hidden" name="address"
value="newsletter@fiscalstudy.com"><input
type="hidden" name="Subject"
value="Newsletter Subscription"><input
type="hidden" name="next_url"
value="http://www.fiscalstudy.com/nlconf.html"><input
type="hidden" name="mandatory"
value="name city email agree"><input
type="hidden" name="errorpage"
value="nlformerror.html"><table border="0"
width="510">
<tr>
<td><table border="0" cellpadding="2"
cellspacing="0" width="500">
<tr>
<td align="right"><font
size="2"
face="Verdana,Geneva"><b>Name:</b></font></td>
<td><input type="text"
size="30" name="Name"></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right"><font
size="2"
face="Verdana,Geneva"><b>City:</b></font></td>
<td><input type="text"
size="30" name="City"> </td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right"><font
size="2"
face="Verdana,Geneva"><b>State/Country:</b></font></td>
<td><input type="text"
size="30"
name="State/Country"> </td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right"><font
size="2"
face="Verdana,Geneva"><b>E-mail:</b></font></td>
<td><input type="text"
size="30" name="Email"> </td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="right"><p
align="left"><font
face="Trebuchet MS"><input
type="checkbox" name="agree"
value="yes"> By clicking
&quot;Subscribe&quot;, I
agree to the </font><a
href="javascript:openup2('http://www.fiscalstudy.com/nlterms.html','nlterms')"
onmouseover="this.style.color='red'"
onmouseout="this.style.color='black'"><font
face="Trebuchet MS">Terms of
Use</font></a><font
face="Trebuchet MS"> of the
newsletter.</font></p>
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right"><input
type="submit"
value="Subscribe"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>

Garadon
06-06-2003, 09:49 PM
And here is your answer. this code won't let u submit the form if any field is left empty.




<html>
<head>
<script>
function validate()
{
for(i=0;i<document.form1.elements.length;i++)
{
if(document.form1.elements[i].value=="")
{
alert('Fill Out all fields');
return false;
}
}
document.form1.submit();
}
</script>
</head>
<body>
<form name="form1"
action="http://us.geocities.yahoo.com/forms?login=fiscalstudy"
method="post">
<input type="hidden" name="address"
value="newsletter@fiscalstudy.com"><input
type="hidden" name="Subject"
value="Newsletter Subscription"><input
type="hidden" name="next_url"
value="http://www.fiscalstudy.com/nlconf.html"><input
type="hidden" name="mandatory"
value="name city email agree"><input
type="hidden" name="errorpage"
value="nlformerror.html"><table border="0"
width="510">
<tr>
<td><table border="0" cellpadding="2"
cellspacing="0" width="500">
<tr>
<td align="right"><font
size="2"
face="Verdana,Geneva"><b>Name:</b></font></td>
<td><input type="text"
size="30" name="Name"></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align="right"><font
size="2"
face="Verdana,Geneva"><b>City:</b></font></td>
<td><input type="text"
size="30" name="City"> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align="right"><font
size="2"
face="Verdana,Geneva"><b>State/Country:</b></font></td>
<td><input type="text"
size="30"
name="State/Country"> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align="right"><font
size="2"
face="Verdana,Geneva"><b>E-mail:</b></font></td>
<td><input type="text"
size="30" name="Email"> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
<td align="right"><p
align="left"><font
face="Trebuchet MS"><input
type="checkbox" name="agree"
value="yes"> By clicking
"Subscribe", I
agree to the </font><a
href="javascriptpenup2('http://www.fiscalstudy.com/nlterms.html','nlterms')"
onmouseover="this.style.color='red'"
onmouseout="this.style.color='black'"><font
face="Trebuchet MS">Terms of
Use</font></a><font
face="Trebuchet MS"> of the
newsletter.</font></p>
</td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td align="right"><input type="Button"
value="Subscribe" onclick="validate();"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>

ssskaya
06-06-2003, 10:01 PM
Great!

Thanks a lot! (It doesn't work with the tick box tough)

----

So, I won't need an error page with this script, right?

Garadon
06-06-2003, 10:50 PM
put this instead of the function you had.
-with it you have to check the checkbox.
-u can put an attribute on the fields called 'faultDescription'
exemple: <input type="checkbox" name="agree" value="yes" faultDescription="You have to agree to the terms, to subscribe">
it gives a more saying faultdescription



function validate()
{
for(i=0;i<document.form1.elements.length;i++)
{
if(document.form1.elements[i].type.toLowerCase()=='checkbox')
{
if(document.form1.elements[i].checked==false)
{
if(document.form1.elements[i].faultDescription=="")
{
alert('Fill Out all fields');
return false;
}
else
{
alert(document.form1.elements[i].faultDescription);
return false;
}
}
}
else
{
if(document.form1.elements[i].value=="")
{
if(document.form1.elements[i].faultDescription=="")
{
alert('Fill Out all fields');
return false;
}
else
{
alert(document.form1.elements[i].faultDescription);
return false;
}
}
}
}
document.form1.submit();
}

ssskaya
06-06-2003, 11:44 PM
Thanks again!

This is even a better script.

It worked all fine.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum