3 Replies Latest reply on Oct 29, 2008 6:30 PM by Kronin555

    Application.cfc Form Validation

      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.
        • 1. Re: Application.cfc Form Validation
          Dan Bracuk Level 5
          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.
          • 2. Re: Application.cfc Form Validation
            Level 1
            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.
            • 3. Re: Application.cfc Form Validation
              Kronin555 Level 1
              > 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>)