chapter31

development in a land far far away…

at the moment

History is not what happened. History is what was written down.

I came across something strange today when developing a web form.

Basically I had a form field with a name/id of “restoration_required” but when I submitted the form I got the following error:

Form Error

Now Geoff Bowers happened to be standing nearby and was kind enough to point out that this looked like a <cfform> validation error, only I wasn’t using cfform!

A quick test (on WinXP, CFMX 7.0.2) showed everything working as expected when I renamed the field as “restoration_isRequired”.

Of course what was really strange was the fact that this was happening when using a normal <form> tag…not <cfform>.

Update 25th April 2007

In response to Todd’s last comment I did a little bit of testing, and when I create a <cfform> ColdFusion will (as expected) generate an HTML form for me.

If I then add the validation attributes (for validateat=”onserver”) ColdFusion will validate any fields where I specify “required=’true’”. In that situation I will get the same error message as before…not that I know where you’d use this because you don’t really seem to get any control over the message!

But…

Even with a <cfform> if I name a field something which ends with “_required” I get that server side validation message whether I’ve entered a value or not!

Sample form

Submitting this gives me the following error:

Form Error 2

In my opinion that is a bug which basically means whether you’re using <cfform> or <form> you can’t name any fields ending with “_required”.


Related Pages

8 Responses to “Unwanted ColdFusion form validation”

  1. s/strange/expected behaviour/

    Tom Chiverton

  2. Yeah, I think that is such a silly form of form validation. I with that was something that could be turned off. Does anyone actually use that any more?

    I have had to change the way I name date variables in general just to work around that. Where I used to have “start_date”, I now have to have “date_started” because “_date” validates as a date.

    I think this was in use back in like CF 2 or something when error handling was much more difficult.

    Ben Nadel

  3. todd sharp

  4. Hi Todd,

    I remember reading your post, note the difference here is that I wasn’t using cfform, just a plain old form tag.

    Odd eh?

    Michael Sharman

  5. Remember though - cfform just creates a on the client. There must be some automatic validation on the server when a form is submitted regardless of the tag used to create the form. How else would CF know to validate on the action page other then by creating form fields with the suffix syntax that they’ve come up with? I do see how you’d get tripped up though.

    todd sharp

  6. grrr..stripped my tag -

    “cfform just creates a form…”

    todd sharp

  7. I updated the post with some more info…see the Update area

    Michael Sharman

  8. On a related note, form variables named with “_time” will burn you in a similarly mysterious manner. http://brad.melendy.com/?p=11

    Brad

Leave a Reply