Skip to main content
Inspiring
May 29, 2007
Question

Data Validation

  • May 29, 2007
  • 4 replies
  • 373 views
I have a form (below) that uses the <cfform> tags with the "required" attributes to validate that the user has entered info and not left a required field blank. This form works correctly on my local machine. For example, if I leave all the fields blank and click the register button I get a JS popup prompting the user to provide the required data. Now, when I put this file to the Register.com server which is using the same version of coldfusion(which is activated) as my local machine the data validation part is not functioning and the user is sent directly to the thank you for registering page regardless of whether he puts any of the fields in, other than the password fields because they are forced to match via <cfif><cfelseif> statements. I spoke with Register.com and they claim it is a coding issue even though it works great locally. Anyone have a suggestion, does Register.com not have a JS plugin enabled?
Thanks in advance!

<cfform method="post" name="form1" action="#CGI.SCRIPT_NAME#" >
<table align="center">
<tr valign="baseline">
<td nowrap align="right">First Name:</td>
<td>
<cfinput type="text" name="firstName"
value="#FORM.firstName#"required="yes"
message="You must enter a first name!"
size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Last Name:</td>
<td>
<cfinput type="text" name="lastName"
value="#FORM.lastName#" required="yes"
message="You must enter a last name!"size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Email Address:</td>
<td>
<cfinput type="text" name="email"
value="#FORM.email#"required="yes"
message="You must enter an email address!" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Password:</td>
<td>
<cfinput type="password" name="password" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Confirm Password:</td>
<td>
<cfinput type="password" name="password2" value="" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Register"></td>
</tr>
</table>
<input type="hidden" name="MM_InsertRecord" value="form1">
</cfform>
    This topic has been closed for replies.

    4 replies

    Inspiring
    May 29, 2007
    Regarding how to code for users who have js disabled, use cold fusion code when processing your variables. Among the things you can use:

    if (len(trim(form.textbox)) is 0 )
    textbox not filled in

    if (isDate(form.textbox) is false)
    not a valid date

    if (form.textbox lt 0 or form.textbox gt 10)
    outside specified range

    there is also an isValid function you can use. Details are in the cfml reference manual. If you don't have one, the internet does.
    Inspiring
    May 29, 2007
    Found the problem. The sorce code is referencing the CFIDE folder which I did not realize had to be uploaded I though all of those folders would be generated when they enabled coldfusion server side. Oh well Live, Code and Learn. Still need advice on coding for users that have JS disabled in their browser. Thanks Dan
    Inspiring
    May 29, 2007
    Here is the view code reults:
    <script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
    <script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>
    <script type="text/javascript">
    <!--
    function _CF_checkform1(_CF_this)
    {
    //reset on submit
    _CF_error_exists = false;
    _CF_error_messages = new Array();
    _CF_error_fields = new Object();
    _CF_FirstErrorField = null;
    //form element firstName required check
    if( !_CF_hasValue(_CF_this['firstName'], "TEXT", false ) )
    {
    _CF_onError(_CF_this, "firstName", _CF_this['firstName'].value, "You must enter a first name!");
    _CF_error_exists = true;
    }
    //form element lastName required check
    if( !_CF_hasValue(_CF_this['lastName'], "TEXT", false ) )
    {
    _CF_onError(_CF_this, "lastName", _CF_this['lastName'].value, "You must enter a last name!");
    _CF_error_exists = true;
    }
    //form element email required check
    if( !_CF_hasValue(_CF_this['email'], "TEXT", false ) )
    {
    _CF_onError(_CF_this, "email", _CF_this['email'].value, "You must enter an email address!");
    _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>

    So it is apperently a server side issue. What do thay need to do to fix this and how do I code to handle user having javascript disabled.
    Inspiring
    May 29, 2007
    Browse to the form on register.com and view the source code. Look for the js that is supposed to validate your form. If it's not there, the problem is with your host. If it is, it's with you.

    Remember that users can disable javascript, in which case you have to write code to handle that.