Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Application.cfc Form Validation

New Here ,
Oct 29, 2008 Oct 29, 2008
Hi all. I posted this question on the site I got the example from, but they removed my question for whatever reason so I'll try here:

Please click the link for the code: Click Here

I tried this example, and it works, however a couple of things I'm trying to figure out:

1. The validation errors change their order each time you re-submit, is there a way to control that?

2. I tried populating the form elements with what was posted, but the form isn't posting anything, and I'm looking to see if anyone else has this problem


Thanks.
TOPICS
Advanced techniques
581
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 29, 2008 Oct 29, 2008
I didn't visit your page. The subject line suggests that you are trying to do form validation in an application.cfc file. Bad idea. Do it in another file somewhere.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 29, 2008 Oct 29, 2008
Hey.. Not sure what happened to my 2 points above. The preview looked fine before I submitted it. Weird!

Anywho.....

Thanks for your reply Dan.

This (amongst other code) is what they put in there:
<cffunction name="onError" returntype="void">
<cfargument name="exception" required="true" />
<cfargument name="eventName" type="String" required="true" />

<cfif isDefined('exception.StackTrace') AND isDefined('exception.errors')
AND exception.StackTrace contains 'coldfusion.filter.FormValidationException'>
<cfset session.validationError = exception.errors />
<cfset session.stFormData = duplicate( form ) />
<cflocation url="#cgi.HTTP_REFERER#" addtoken="false" />
<cfelse>
<cfthrow object="#exception#" />
</cfif>
</cffunction>

So,why would this be a bad idea?

- - - -
Oh, and if the above code makes it ok to add to Application.cfc, then my quesitons 1 and 2 were:
1. The validation errors return in different orders every time the form is posted, and was wondering how to control this.

2. I couldn't get the form to post any values.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Oct 29, 2008 Oct 29, 2008
LATEST
> The validation errors return in different orders every time the form is posted, and was wondering how to control this.

You can't. That's one of the downsides of using cfform validation.

As to why your form didn't post any values, you're going to need to post your form code (from <cfform...> to </cfform>)
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources