An Architect's View

ColdFusion, Software Design, Frameworks and more...

An Architect's View

cfform and onSubmit

November 5, 2005 · 4 Comments

I've seen a couple of people trip over this so I thought I'd better blog something about the issue... If you use cfform and have your own onSubmit handler to perform custom field validation, you probably have something that looks like this:
<cfform action="someAction.cfm"
method="POST" name="myForm" onSubmit="return
checkFields(this)"
>
If you have any auto-validation on your cfinput forms, ColdFusion MX 7.0.1 will rewrite the onSubmit to call its auto-generated validation Javascript that will in turn call your original onSubmit code. That fixes a bug in earlier versions where either your Javascript would run or the auto-generated Javascript would run, but not both. However, there is a subtle side-effect: the above code stops working. Why is that? CFMX ends up calling checkFields(this) from inside the auto-generated Javascript and this refers to that code, not the original form. The fix is to use a named reference to the form object instead of this:
<cfform action="someAction.cfm"
method="POST" name="myForm" onSubmit="return
checkFields(document.myForm)"
>

Tags: coldfusion

4 responses so far ↓

  • 1 tc // Nov 7, 2005 at 7:57 AM

    Sean,
    I can't find in the CFMX 7.01 documentation how the OnSubmit and OnReset work when dealing with cfforms type=Flash. Does you example in the article work the same with Flashed based CFFORMS?

    Thanks,
    TC
  • 2 Sean Corfield // Nov 7, 2005 at 8:26 AM

    With Flash forms you can't use Javascript - you need to use ActionScript instead. See Ray Camden's &quot;Ask a Jedi&quot; entry on this:

    http://ray.camdenfamily.com/index.cfm/2005/9/20/Ask-a-Jedi-Flash-Form-Custom-Validation
  • 3 Mikhail // Apr 11, 2008 at 6:56 AM

    Hi Sean,
    Since I upgrade to CF MX7 any auto-validation on my cfinput forms stops working,
    On submit only my custom Javascript calls
    Your example working OK on CF 6.1 but auto-validation does not work on CF MX7
    Please advise
    Thanks
  • 4 Sean Corfield // Apr 11, 2008 at 7:06 AM

    @Mikhail, impossible to tell from your brief description. I suggest you post your code on cf-talk and get someone who is still using CFMX 7 to help you (I haven't had access to a local CFMX 7 installation for about 18 months).

Leave a Comment

Leave this field empty: