Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

onSubmit and validation issue

Explorer ,
Nov 05, 2008 Nov 05, 2008
This is my first time posting here and I am new to CF. I took and passed a figleaf course on Cold Fusion and have some other programing background.

The issue that I cannot seem to resolve has to do with onSubmit. Here is some very basic code straight out of my Fast Track to CF class...

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert Artist Form</title>
</head>

<body>

<h2>Insert an Artist</h2>

<cfform name="insArtist">

First Name:
<cfinput type="text" name="FirstName" maxlength="20" required="yes" message="Please input an artist first name." validateat="onserver" /><br/>

Last Name:
<cfinput type="text" name="LastName" maxlength="20" required="yes" message="Please input an artist last name." validateat="onsubmit" /><br/>

<cfinput type="submit" name="Insert" value="Insert Artist" />

</cfform>

</body>
</html>

When I leave the fields blank the onServer message does come up.

If I take out first name and try to verify only Last Name I can click as much as I like on the Submit button but the alert never comes up with the message "Please input an artist last name."

I have set up a system using XP SP3 and the same issue happens on Firefox 3.0.3 or IE 7.

I am using CFEclipse, Apache, and CF8. I have Virtual Hosts set up for my sandbox.

Please let me know if any other information is needed.

Thanks for your help.

Dave
TOPICS
Getting started
905
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Explorer , Nov 06, 2008 Nov 06, 2008
Thanks JR "Bob" Dobbs you pointed me in the right direction.

The issue was how I had set up my virtual directories. Being that I am new to web development I didn't understand how that scripts directory was being accessed. I fixed this issue, with some help from the boss by adding the following to my http.conf file for apache.

# "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
...
Translate
Advisor ,
Nov 05, 2008 Nov 05, 2008
Your code seems to be valid.

Check these items:
1. Are the supporting javascript files accessible to your browser? They are located in /CFIDE/ and are named /CFIDE/scripts/cfform.js and /CFIDE/scripts/masks.js

2. Does your browser have javascript enabled?

3. Is the browser reporting any javascript exceptions?

Also note that the validateAt="onServer" works by adding a hidden form field that instructs the server on what to validate. It can be easily bypassed by a user so I wouldn't rely on it.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 05, 2008 Nov 05, 2008
Error Console in Firefox specifies this line as a problem...

if( !_CF_hasValue(_CF_this['LastName'], "TEXT", false ) )

This is code that is generated by CF on the fly though.. All I'm doing is setting onSubmit.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head><script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Insert Artist Form</title>

<script type="text/javascript">
if (window.ColdFusion) ColdFusion.required['FirstName']=true;
</script>

<script type="text/javascript">
if (window.ColdFusion) ColdFusion.required['LastName']=true;
</script>
<script type="text/javascript">
<!--
_CF_checkinsArtist = function(_CF_this)
{
//reset on submit
_CF_error_exists = false;
_CF_error_messages = new Array();
_CF_error_fields = new Object();
_CF_FirstErrorField = null;

//form element LastName required check
if( !_CF_hasValue(_CF_this['LastName'], "TEXT", false ) )
{
_CF_onError(_CF_this, "LastName", _CF_this['LastName'].value, "Please input an artist last name.");
_CF_error_exists = true;
}


//display error messages and return success
if( _CF_error_exists )
{
if( _CF_error_messages.length > 0 )
{
// show alert() message
_CF_onErrorAlert(_CF_error_messages);
// set focus to first form error, if the field supports js focus().
if( _CF_this[_CF_FirstErrorField].type == "text" )
{ _CF_this[_CF_FirstErrorField].focus(); }

}
return false;
}else {
return true;
}
}
//-->

</script>
</head>

<body>

<h2>Insert an Artist</h2>

<form name="insArtist" id="insArtist" action="/content/contactnew.cfm" method="post" onsubmit="return _CF_checkinsArtist(this)">

<!-- First Name:
<input name="FirstName" id="FirstName" type="text" maxlength="20" /><br/> -->

Last Name:
<input name="LastName" id="LastName" type="text" maxlength="20" /><br/>

<input name="Insert" id="Insert" type="submit" value="Insert Artist" /> <input type='hidden' name='FirstName_CFFORMREQUIRED' value='Please input an artist first name.'>

</form>


</body>
</html>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 05, 2008 Nov 05, 2008
Sounds like the supporting javascript files cannot be found by the browser.

Can you browse to /CFIDE/scripts/cfform.js or /CFIDE/scripts/masks.js?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 05, 2008 Nov 05, 2008
Both files are available in C:\dev\CFIDE\scripts on my machine. I have a virtual host set up to get into cfadmin

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.localhost
DocumentRoot "C:\dev\CFIDE"
ServerName www.cf8.localhost
ErrorLog "logs/dummy-host2.localhost-error.log"
CustomLog "logs/dummy-host2.localhost-access.log" common
</VirtualHost>

The CFIDE folder and cfdocs folder are both in a folder called dev where I am hosting my apache root. I notice, though I don't know if it's important, that WEB-INF is in a wwwroot folder like this C:\ColdFusion8\wwwroot.

Any ideas what I can do to fix this? Thanks for replying JR "Bob" Dobbs!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 05, 2008 Nov 05, 2008
You need a directory or virtual directory /CFIDE.

I'm not familiar with Apache, but this link may help.
http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=configuring_08.html#1171424
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 05, 2008 Nov 05, 2008
The virtual directory is Dev/CFIDE. Thanks for working this out with me. Maybe it does have to do with pathing but the directory is there.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Nov 05, 2008 Nov 05, 2008
If you add the attribute scriptSrc="/Dev/CFIDE/scripts" to your cfform tag does the validation work?

Can you browse to /Dev/CFIDE/scripts/cfform.js?
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 05, 2008 Nov 05, 2008
quote:

Originally posted by: JR "Bob" Dobbs
If you add the attribute scriptSrc="/Dev/CFIDE/scripts" to your cfform tag does the validation work?

Can you browse to /Dev/CFIDE/scripts/cfform.js?


The validation still is not working. Also I can get to the cfform.js does exist in /Dev/CFIDE/scripts/cfform.js.

I am heading home but I will pick up on this in the morning and try looking at the pathing some more.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 06, 2008 Nov 06, 2008
LATEST
Thanks JR "Bob" Dobbs you pointed me in the right direction.

The issue was how I had set up my virtual directories. Being that I am new to web development I didn't understand how that scripts directory was being accessed. I fixed this issue, with some help from the boss by adding the following to my http.conf file for apache.

# "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin" should be changed to whatever your ScriptAliased
# CGI directory exists, if you have that configured.
#
<Directory "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>

<Directory "C:\dev\CFIDE">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources