4 Replies Latest reply on Jun 28, 2007 3:23 PM by ForumUser

    Reusing CFFORM controls

      I'm wondering if anyone has a solution for reusing form controls. Let's say I have a specific <cfselect> for states that I want to use in 200 different forms. Of course I can copy/paste it all over the place, but that's bad software development. I'd like to be able to put that CFSELECT in a separate file or function, and just call it.

      Here's and example of what I'm trying to do:

      <CFFORM ...>
      <CFINCLUDE tample="StateSelector.cfm">

      <CFSELECT ...>

      I constantly get the error message "The tag must be nested inside a cfform tag", and I can see why. But that's very limiting when you're designing large systems with CF. Has anyone found a way to do this? It doesn't have to use CFINCLUDE. Any method to allow code resue is fine.

      Thanks in advance.
        • 1. Re: Reusing CFFORM controls
          Charlie Griefer Level 1
          the include would work if you used a <select> over a <cfselect>. is there any compelling reason to use <cfselect> in this case?
          • 2. Re: Reusing CFFORM controls
            ForumUser Level 1
            I want to be able to take full advantage of CFSELECT, CFINPUT, CFCALENDAR, etc. CFSELECT was just used as an example. It'd be nice if I can setup different CFINPUTS and just reuse them in different cfforms. But CF doesn't allow CFINPUT anywhere outside of a CFFORM. So, for example, I can't put CFINPUT inside a CFFUNCTION, and call that function 10 times within a CFFORM. So standardization and code reuse is not an option.

            The same problem goes with CFFORM itself. It does not seem to be extendable. For example, I cannot find a way create a custom tag called MyCFFORM that would embed a CFFORM in it. CF wont' let you put a CFINPUT between MyCFFROM tags.

            So my question is, is there a way to maybe go under the hood, and extend CFFORM, CFINPUT, CFSELECT, etc? Hope it makes sense.
            • 3. Re: Reusing CFFORM controls
              Charlie Griefer Level 1
              personally, i don't use cfform. comes from way back in the day when the cfform generated JS would stomp the JS that I wrote myself. i hear it's gotten better... but old habits and all that.

              as far as taking full advantage of <cfform> and its child elements... you might want to look into some of the JS libraries like jQuery. I believe that it'll offer the same type of functionality that you're getting from cfform (and then some). not to mention that it's easy to extend yourself, as the library files are just .js

              this way you won't be bound by the inability to create modular pieces by the fact that ColdFusion won't allow the cfform elements to be broken up.

              just a suggestion. i'm sure there will be others :)
              • 4. Re: Reusing CFFORM controls
                ForumUser Level 1
                I agree, and I haven't been using CFFORM for the same reasons. I just need to use its Flash and XML capabilities. CFMX 8 is introducing more exotic form elements that are hard to pass on, but CFFORM doens't work with my current framework.