Reputation: 327
i am trying to validate my form so it doesnt accept empty fields. You can see i have tried to do validation on the "Country" using the 'required' property but that doesnt work....
I only want validation done on certain fields: Country, Address, City and ReceptionNumber
Here is my code for the form:
<head>
<title>Office Location Entry Form</title>
<LINK rel="stylesheet" type="text/css" href="css/style.css">
<cfinclude template="CheckUserLogin.cfm">
</HEAD>
<body background="FFFFFF" bgcolor="#FFFFFF">
<P class="paratitle"><br> Country Offices Entry Form <BR>
<P class="normal">Please fill in as many fields as possible. Please include the country dial code when entering phone or fax numbers.</p>
<!--- Entry form --->
<FORM name="officeLocations" action="officeLocations_EntryAction.cfm" method="post" onSubmit="return ValidateInput(this);">
<TABLE>
<!--- Field: office_locations.Country --->
<TR>
<TD valign="top" class="normal"> Country </TD>
<TD valign="top" class="normal">
<input type="text" name="Country" size="30" maxlength="510" class="input" required="yes" message="You must enter a first country.">
</TD>
</TR>
<!--- Field: office_locations.address --->
<TR>
<TD valign="top" class="normal"> Address</TD>
<TD valign="top" class="normal">
<INPUT type="text" name="address" size="30" value="" maxLength="510" class="input">
</TD>
</TR>
<!--- Field: office_locations.address2 --->
<TR>
<TD valign="top" class="normal"> Address 2</TD>
<TD valign="top" class="normal">
<INPUT type="text" name="address2" size="30" value="" maxLength="510" class="input">
</TD>
</TR>
<!--- Field: office_locations.address3--->
<TR>
<TD valign="top" class="normal"> Address 3</TD>
<TD valign="top" class="normal">
<INPUT type="text" name="address3" size="30" value="" maxLength="510" class="input">
</TD>
</TR>
<!--- Field: office_locations.address5--->
<TR>
<TD valign="top" class="normal"> Address 4</TD>
<TD valign="top" class="normal">
<INPUT type="text" name="address4" size="30" value="" maxLength="510" class="input">
</TD>
</TR>
<!--- Field: office_locations.address4 --->
<TR>
<TD valign="top" class="normal"> City</TD>
<TD valign="top" class="normal">
<INPUT type="text" name="city" size="30" value="" maxLength="510" class="input">
</TD>
</TR>
<!--- Field: office_locations.postcode --->
<TR>
<TD valign="top" class="normal"> Postal code</TD>
<TD valign="top" class="normal">
<INPUT type="text" name="postcode" size="30" value="" maxLength="510" class="input">
</TD>
</TR>
<!--- Field: office_locations.receptionnumber --->
<TR>
<TD valign="top" class="normal"> Reception number</TD>
<TD valign="top" class="normal">
<INPUT type="text" name="receptionnumber" size="30" value="" maxLength="510" class="input">
</TD>
</TR>
<!--- Field: office_locations.mainnumber --->
<TR>
<TD valign="top" class="normal"> Main number</TD>
<TD valign="top" class="normal">
<INPUT type="text" name="mainnumber" size="30" value="" maxLength="510" class="input">
</TD>
</TR>
<!--- Field: office_locations.faxnumber --->
<TR>
<TD valign="top" class="normal"> Fax number</TD>
<TD valign="top" class="normal">
<INPUT type="text" name="faxnumber" size="30" value="" maxLength="510" class="input">
</TD>
</TR>
<INPUT type="hidden" name="timestamp" value="<CFOUTPUT>#DateFormat(Now())#, #TimeFormat(Now())#</CFOUTPUT>" size="">
<INPUT type="hidden" name="username" value="<CFOUTPUT>#Session.FirstName# #Session.LastName#</CFOUTPUT>" size="">
<INPUT type="hidden" name="NTusername" value="<cfoutput>#Session.NtUserName#</cfoutput>" size="">
</TABLE>
<P>
<input type="image" src="IMAGES/AddItButton.gif" align="absmiddle">
</FORM>
</body>
</html></HTML>
Thanks
Upvotes: 0
Views: 1737
Reputation: 29870
As requested I am posting this as an answer, but I cannot stress enough that this approach is a very poor one. It does, however, answer your question.
From the comments attached to the question:
Do you mean the
<input>
tags to be<cfinput>
, and for this to be a<cfform>
? As far as I can tell HTML 5 has a required attribute on , but no message. And HTML 4 has neither. But both are attributes of<cfinput>
..? Oh, and you just shouldn't be using<cfform>
and<cfinput>
anyhow. Do the job properly with Javascript (and matching server-side validation).
Upvotes: 1