With a little side of applesauce...

Tuesday, January 30, 2007

CFMX 7 cfform validation not working (w/ multiple virtual hosts)

When using the tag, and form validation using , etc., the validation is not working. If you create the as follows:


<body>
<cfform action="valid.cfm" method="post" >
<cfinput name="name" type="text" required="yes" message="please enter name" />name

<cfinput name="submit" type="submit" value="submit" />
</cfform>
</body>
</html>


And, then view the rendered HTML:



<!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=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" xsrc="/CFIDE/scripts/cfform.js"></script>
<script type="text/javascript" xsrc="/CFIDE/scripts/masks.js"></script>
<script type="text/javascript">
<!--
function _CF_checkCFForm_1(_CF_this)
{
//reset on submit
_CF_error_exists = false;
_CF_error_messages = new Array();
_CF_error_fields = new Object();
_CF_FirstErrorField = null;



you will see that the tag uses “/CFIDE/scripts/cfform.js” as the location from which to include the javascript needed to validate the forms.
In a virtual host, or multi-homed, environment, this path is not correct, therefore, form validation is bypassed.

WORKAROUND: Thankfully, the tag has a “scriptSrc” attribute that can be used to set the correct location of the javascript files:



<body>
<cfform action="valid.cfm" method="post" scriptSrc="http://www.location.cfide.com/cfide/scripts/cfform.js" >
<cfinput name="name" type="text" required="yes" message="please enter name" />name

<cfinput name="submit" type="submit" value="submit" />
</cfform>
</body>
</html>


This sets the correct location for the javascript files, and validation works:


<!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=iso-8859-1" />
<title>Untitled Document</title>
<script type="text/javascript" xsrc="http://www.location.cfide.com/cfide/scripts/cfform.js"></script>
<script type="text/javascript" xsrc="/cfide/scripts/masks.js"></script>
<script type="text/javascript">
<!--
function _CF_checkCFForm_1(_CF_this)
{
//reset on submit
_CF_error_exists = false;
_CF_error_messages = new Array();


Check this link out for more information:
http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_18653

No comments: