Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Form Validation Problem 1

Status
Not open for further replies.

RSedlacek

Programmer
Oct 5, 1998
59
0
0
US
I'm having trouble using the <CFINPUT TYPE="TEXT" REQUIRED="Yes"> tag. When I load the form template in my browser, and purposefully leave the TEXT input blank it doesn't throw an error message like it should.

Here is the form code:
Code:
<CFFORM ACTION="testaction.cfm" METHOD="POST"> 

Please Enter Your Name<BR>
<CFINPUT 
	TYPE="text"
	NAME="Contact"
	SIZE="20"
	REQUIRED="Yes"
	MESSAGE="Name is required!">

<INPUT TYPE="submit" VALUE="Submit">

</CFFORM>

Here is the action code:
Code:
<CFOUTPUT>

Thanks for your input #form.Contact#!

</CFOUTPUT>

The form is located at
I'm going crazy trying to figure this out. Does anyone have any ideas?
 
Try this:

I just tried it and it worked:

----------------------------------
<CFFORM ACTION="testaction.cfm" METHOD="POST" NAME="submit">

Please Enter Your Name<BR>



<CFINPUT TYPE="text" NAME="Contact" SIZE="20" REQUIRED="Yes" MESSAGE="Name is required!">

<INPUT TYPE="submit" VALUE="Submit">

</CFFORM>
-------------------------------------

I just added a name to the form.
 
Yes, but what happens when you do not add a name to the form? Do you get an error message? That is what it is suppose to do, but doesn't.
 
Try this thread.

thread232-934793

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Great solution bomboy! Works great, and I will probably use that from now on.

However, I would like to know why my original coding won't work. Does anyone know why it doesn't work? It should. Sure would cut down on the amount of coding required if it did work.

Randy
 
try adding 'value = "" ' and see what happens. It's a swing in the dark, like I said I don't use <cfform> stuff. This may force an empty string to start with. not sure.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Thanks for attempting the swing bombboy, but unfortunately it missed. Anyone else care to take a swing at it?
 

have you got scripting turned on in your browser, as the code that you posted at the start works for me on our server.

CFMX 6.1, IE 6, win XP SP 2

Have you got a error in the bottom left hand corner of your browser window?

Hope this helps!

Tony
 
Yes, scripting is turned on. And no...there is not any error anywhere.
 
I copied and pasted exactly what was posted and it works fine. If I view source I get this

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/html4/loose.dtd">[/URL]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/CFIDE/scripts/cfform.js"></SCRIPT>

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--

function  _CF_checksubmit(_CF_this)
{
	if  (!_CF_hasValue(_CF_this.Contact, "TEXT" ))
	{
		if  (!_CF_onError(_CF_this, _CF_this.Contact, _CF_this.Contact.value, "Name is required!"))
		{
			return false;
		}
	}

	return true;
}


//-->
</SCRIPT>

</head>

<body>
<FORM NAME="submit" ACTION="testaction.cfm" METHOD="POST" onSubmit="return _CF_checksubmit(this)">  

Please Enter Your Name<BR>



<INPUT TYPE="text" NAME="Contact" SIZE="20">

<INPUT TYPE="submit" VALUE="Submit">

</FORM> 

</body>
</html>

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
It's wierd. If I copy the CF code and run it, it works. If I view source and copy/paste (from RSedlacek's link), it does just what RSedlacek is describing.



Hope This Helps!

Ecobb
Beer Consumption Analyst

"My work is a game, a very serious game." - M.C. Escher
 
Good point.
I ran the link and when you submit it you will get an error on the page.

line: 14
Error: object expected

line 14 is:
if (!_CF_hasValue(_CF_this.Contact, "TEXT" ))

I think _CF_hasValue() is coming from the .js file, I don't se it mentioned elsewhere. maybe it can't find the file. check for it in the scripts folder under cfide maybe.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
My service provider fixed it by doing the following:

"It appears that you were using java script for the form validation and calling it from the cfide directory.
What I did was create a virtual directory called CFIDE and mapped it to the cfide in the webroot of default website."

The java script was automatically generated from the use of CF tags. CF uses tags to call the jscript.
 
woo hoo good guess

bombboy said:
I think _CF_hasValue() is coming from the .js file, I don't se it mentioned elsewhere. maybe it can't find the file. check for it in the scripts folder under cfide maybe.

Thanks for posting the solution.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Thanks bombboy for heading us in the right direction.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top