Form Validation

I was hoping, someone, Hatton maybe? would be able to help me Im trying to use cfform and cfinput for validation. However, although jscript is turned on it doesnt seem to work. Its very simple code
Code:
 <cfform action="action/template" method="post"> User Name:<cfinput name="uname" type="text" required="yes" message="please enter a user name"/> </cffrom>

I wouldnt mind using any other method to validate as long as it works. Thanks for the help.
 
atomi said:
I was hoping, someone, Hatton maybe? would be able to help me Im trying to use cfform and cfinput for validation. However, although jscript is turned on it doesnt seem to work. Its very simple code
Code:
 <cfform action="action/template" method="post"> User Name:<cfinput name="uname" type="text" required="yes" message="please enter a user name"/> </cffrom>

I wouldnt mind using any other method to validate as long as it works. Thanks for the help.
Have you tried your code or are you just looking for syntax?
 
the syntax is correct. the problem is the code just doesnt seem to do what its suppose to. I have an input type image that submits the form (for aesthetics) and no matter what is entered the form is processed. My impression of the command required="yes" was that it would not submit a form unless there was a text string entered. But the damn form keeps getting sent even if the cfinput is empty which creates a mess in db.

ive even trid javascript
Code:
		function validateFields(form) {
if (form.login.value == "") {
				alert('Please Enter a User Name');
				form.login.focus();
				return false; 
			}
return true;
and i checked the browser for support. Its frustrating to say the least.
thanks hatton
 
atomi said:
the syntax is correct. the problem is the code just doesnt seem to do what its suppose to. I have an input type image that submits the form (for aesthetics) and no matter what is entered the form is processed. My impression of the command required="yes" was that it would not submit a form unless there was a text string entered. But the damn form keeps getting sent even if the cfinput is empty which creates a mess in db.

ive even trid javascript
Code:
		function validateFields(form) {
if (form.login.value == "") {
				alert('Please Enter a User Name');
				form.login.focus();
				return false; 
			}
return true;
and i checked the browser for support. Its frustrating to say the least.
First off, take a look at the source of the page that is being generated with the CFForm option and you'll see some pregenerated Javascript. Personally I prefer to use server-side validation (check the data after the form has been submitted and then reload the form hilighting the missing fields) over JS simply because it gives me a lot more power over the validation.

Not sure if you've been there or not yet but take a poke at http://livedocs.macromedia.com/coldfusion/6.1/htmldocs/tags-p65.htm#wp1100379 which is the LiveDoc entry for CFINPUT.

HTH
Hatton
 
Id like to use server side validation. I was doing some cut and paste coding and funny thing. theres a difference between
Code:
?text?
and
Code:
 "text"

so this was my problem.
thanks for the replys Hatton. When Im done with this site ill post it up see what you think.
also if you can give me some pointers on server side validation. Id like to have red text pop up to the side of the input field if its not validated. currently i get the "you've broken the internet" coldfusion box.
 
atomi said:
Imgoing ahead and using a technique from EAsyCFM at http://tutorial192.easycfm.com/ I also took a gander at your form page at your 3-ld site. Could you post or tell how you did the dual password verification? That is if your feeling helpful.
thanks again Hatton.

I took a peek at that tutorial and it looks like a good one... Just for grins I'm including the code for the registration page on 3-ld.com so you can see it. I know that I need to move the queries over to CFStoredProc calls, just haven't had the time to recently.

Code:
<cfset PageTitle="Register for Account">

<cfparam name="form.cFirstName" default="">
<cfparam name="form.cLastName" default="">
<cfparam name="form.cEmail" default="">
<cfparam name="form.cUsername" default="">
<cfparam name="form.cAIM" default="">
<cfparam name="form.cMSN" default="">
<cfparam name="form.cICQ" default="">
<cfparam name="form.cYIM" default="">
<cfscript>
	form.dSince = Now();
	form.dLast = Now();
	form.lActive = 1;
	form.nPos = 0;
	form.nNeut = 0;
	form.nNeg = 0;
	form.nUserTypes_id = 2;
	ErrorText = "";
</cfscript>

<cfif IsDefined("form.Cancel")>
	<cflocation url="index.cfm">
</cfif>

<cfif IsDefined("form.Submit")>
	<cfquery name="qCheckUser" datasource="#session.datasource#"  username="#session.db_un#" password="#session.db_pw#">
		up_get_users @cUsername = '#form.cUsername#'
	</cfquery>
	<cfif qCheckUser.RecordCount>
		<cfset ErrorText = "That username is already in use, please select a different name and try again.">
	<cfelse>
		<cfif (Form.cPassword NEQ Form.cPassword2) OR NOT Len(Form.cPassword)>
			<cfset ErrorText = "You must enter a valid password and verify it correctly.  Please try again.">
		<cfelse>
			<cfset GoodAdd = 1>
			<cfquery name="qAddUser" datasource="#session.datasource#"  username="#session.db_un#" password="#session.db_pw#">
				up_set_user @nUsers_id = 0, 
					@cFirstName = '#form.cFirstName#', 
					@cLastName = '#form.cLastName#', 
					@cEmail = '#form.cEmail#', 
					@cUsername = '#form.cUsername#', 
					@cPassword = '#form.cPassword#', 
					@cAIM = '#form.cAIM#', 
					@cYIM = '#form.cYIM#', 
					@cICQ = '#form.cICQ#', 
					@cMSN = '#form.cMSN#', 
					@nUserTypes_id = #form.nUserTypes_id#,
					@dSince = #form.dSince#, 
					@dLast = #form.dLast#, 
					@nPos = #form.nPos#, 
					@nNeut = #form.nNeut#, 
					@nNeg = #form.nNeg#
			</cfquery>
		</cfif>
	</cfif>
</cfif>

<cfinclude template="includes/newHeader.cfm">
<cfinclude template="includes/newTop.cfm">
<cfinclude template="includes/newsidebar.cfm">
<cfinclude template="includes/newmiddle.cfm">
<cfform action="register.cfm" method="post">
	<cfif NOT IsDefined("GoodAdd")>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
            <td width="26%"><div align="center"><img src="images/rambo.jpg" width="150" height="156"></div></td>
            <td colspan="2"><div align="center" class="BigHeader">User Registration 
                Form</div>
			<cfif Len(ErrorText) GT 0>
				<p align="center" class="Error"><cfoutput>#ErrorText#</cfoutput></p>
			</cfif></td>
          </tr>
          <tr> 
            <td colspan="3"><hr></td>
          </tr>
          <tr> 
            <td class="SmallHeader">User Information</td>
            <td width="1%">&nbsp;</td>
            <td width="73%">&nbsp;</td>
          </tr>
          <tr> 
            <td> <div align="right">First Name</div></td>
            <td>&nbsp;</td>
            <td> <cfinput name="cFirstName" type="text" value="#form.cFirstName#" size="50" maxlength="75" required="yes" message="You must enter your first name" id="cFirstName"></td>
          </tr>
          <tr> 
            <td> <div align="right">Last Name</div></td>
            <td>&nbsp;</td>
            <td> <cfinput name="cLastName" type="text" value="#form.cLastName#" size="50" maxlength="75" required="yes" message="You must enter your last name" id="cLastName"></td>
          </tr>
          <tr> 
            <td> <div align="right">Email Address</div></td>
            <td>&nbsp;</td>
            <td> <cfinput name="cEmail" type="text" value="#form.cEmail#" size="50" maxlength="150" required="yes" message="You must enter a valid email address" id="cEmail"></td>
          </tr>
          <tr> 
            <td><div align="right">Username</div></td>
            <td>&nbsp;</td>
            <td> <cfinput name="cUsername" type="text" value="#form.cUsername#" size="50" maxlength="50" required="yes" message="You must enter a username" id="cUsername"></td>
          </tr>
          <tr> 
            <td><div align="right">Password</div></td>
            <td>&nbsp;</td>
            <td> <cfinput name="cPassword" type="password" id="cPassword" maxlength="50"></td>
          </tr>
          <tr> 
            <td><div align="right">Repeat Password</div></td>
            <td>&nbsp;</td>
            <td> <cfinput name="cPassword2" type="password" id="cPassword2" maxlength="50"></td>
          </tr>
          <tr> 
            <td class="SmallHeader">Optional Contact Info</td>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
          </tr>
          <tr> 
            <td><div align="right">AOL Messenger</div></td>
            <td>&nbsp;</td>
            <td> <cfinput name="cAIM" type="text" id="cAIM" value="#form.cAIM#" maxlength="75"></td>
          </tr>
          <tr> 
            <td><div align="right">MSN Messenger</div></td>
            <td>&nbsp;</td>
            <td><cfinput name="cMSN" type="text" id="cMSN" value="#form.cMSN#" maxlength="75"></td>
          </tr>
          <tr> 
            <td><div align="right">Yahoo Messenger</div></td>
            <td>&nbsp;</td>
            <td><cfinput name="cYIM" type="text" id="cYIM" value="#form.cYIM#" maxlength="75"></td>
          </tr>
          <tr> 
            <td><div align="right">ICQ UIN</div></td>
            <td>&nbsp;</td>
            <td><cfinput name="cICQ" type="text" id="cICQ" value="#form.cICQ#" maxlength="75"></td>
          </tr>
          <tr> 
            <td colspan="3"><hr></td>
          </tr>
          <tr> 
            <td colspan="3"><div align="center"> 
                <input type="submit" name="Submit" value="Submit Registration">
                <input type="reset" name="Submit2" value="Reset ">
                <input name="Cancel" type="button" id="Cancel" value="Cancel Registration" onClick="self.location='index.cfm';">
              </div></td>
          </tr>
        </table> 
      <cfelse>
	   <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr> 
		  	<td><div align="center" class="BigHeader">User Account Created Successfully</div>
			<p>Use the link on the left to go to the Login page.</p>
			</td>
            <td width="26%"><div align="center"><img src="images/rambo.jpg" width="150" height="156"></div></td>
          </tr>
		</table>
	  </cfif>
      </cfform>
      <cfinclude template="includes/newbottom.cfm">

If you want a translation let me know.

Cheers!
Hatton
 
thats alot of code! I was interested in this bit of code here
Code:
<cfif (Form.cPassword NEQ Form.cPassword2) OR NOT Len(Form.cPassword)>
I feel silly for not thinking of that. Anyway. I ve got another problemo Im researching atm. Until Later!
 
how do i serverside validate a checkbox for "I agree to terms of use" ?

I tried passing the name of the checkbox
Code:
<input type="checkbox" name="terms">
but i get an error in my action page saying form.terms is undefined.
edit:
NM i got it. I used this code
Code:
<cfelseif form.terms is not "yes">
 
atomi said:
how do i serverside validate a checkbox for "I agree to terms of use" ?

I tried passing the name of the checkbox
Code:
<input type="checkbox" name="terms">
but i get an error in my action page saying form.terms is undefined.
edit:
NM i got it. I used this code
Code:
<cfelseif form.terms is not "yes">

Checkboxes are returned in the form structure only if they are selected. What I do to handle them is have a line in my validation that reads

<cfparam name="form.checkbox" default="No">

That way the field exists regardless of whether or not the box is checked.

Hatton
 
atomi said:
hey hatton i found you on sitepoiont. heh. really old post from almost 5 years ago.
http://www.sitepoint.com/forums/showthread.php?t=5224
anyway thanks for the help.
atomi
Heh, yep that's me alright - though my callsign has changed (was KC5SIG is now NY5I... it's a Ham Raido thing, don't worry)

Jonesee and the rest of the gang over at Sitepoint are really good. I've just gotten too busy to maintain a presence on all the different lists. Hell, I hardly have time to post on my own websites and personal blog let alone monitor message boards!

Hatton
 
Back
Top