ColdFusion's in-built form validation

July 01, 2008

Does anyone actually use ColdFusion's in-built form validation? I don't mind the _cfformxyz suffixes it's the _date, _time, _range and _required suffixes which really bug me. If nobody uses this legacy feature any more can we just get rid of it? A setting in Application.cfc to turn it off would do!

If you haven't stumbled across this feature and the problems it causes then let me give you an example:

<p>New Vacancy Form</p>
<form action="index.cfm" method="post">
  <table summary="New vacancy form">
    <tr>
      <th>Job Title</th>
      <td><input type="text" name="job_title" value="" /></td>
    </tr>
    <tr>
      <th>Salary Range</th>
      <td><input type="text" name="salary_range" value="" /></td>
    </tr>
    <tr>
      <th>Driving Licence Required</th>
      <td><input type="checkbox" name="licence_required" value="Yes" /></td>
    </tr>
    <tr>
      <th>Closing Date</th>
      <td><input type="text" name="closing_date" value="" /></td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" name="submit" value="submit" /></td>
    </tr>
  </table>
</form>

If you tick the Driving Licence Required box and submit this form, then regardless of what code you have in myscript.cfm you will see this error message:

Form entries are incomplete or invalid.

  • Yes

Go back and correct the problem.

I have also used in my example reserved field name suffixes, so that could create problems in the future if we add more form fields. For more information on ColdFusion's in-built form validation view the Validating form data using hidden fields on livedocs.


4 comments

  1. I soon found the limitations of the built-in JavaScript validation. If you get anywhere need a demanding UI validation model you'll be cursing CF. I'd invest your time in learning a proper JS framework like jQuery and leave CF to what it does best: server-side business logic and db interaction.

    Comment by dickbob – July 01, 2008
  2. @dickbob - I'm with you all the way! I'm a big fan of jQuery and the jQuery validation form plugin (http://bassistance.de/jquery-plugins/jquery-plugin-validation/)
    I just find it annoying that you have to be careful when naming your fields so that you don't get caught out by ColdFusion's form validation.

    Comment by John Whish – July 01, 2008
  3. Yeah, my first exposure to this was I think using the "_date" ending on a javascript variable name. I had no idea that CF stuck client-side validation on these fields even if you didn't use a CFFORM. I've had to make changes in how I name variables in order to avoid having this happen. I'd be thrilled if there were a CFSETTING or something like that which would shut it off!

    Comment by Matt Newby – July 02, 2008
  4. beginning with about cf5, when we penned our first coding guidelines/standards, we specifically addressed this. So I rarely gave it much thought afterwards.

    when 8 came out we noticed that they added quite a few more versions that do this

    http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=validateData_10.html#1154690

    Also, I could be wrong but I thought this performed server side rather than client side javascript validation. I would swear the first time I came across it I was using a browser without javascript.

    Comment by Matt – July 03, 2008

Leave a comment

If you found this post useful, interesting or just plain wrong, let me know - I like feedback :)

Please note: If you haven't commented before, then your comments will be moderated before they are displayed.