9 Replies Latest reply on May 18, 2011 10:30 AM by dujsu

    Dynamic CFML form elements

    dujsu Level 1

      Is there a trick to getting the cfinput to display? The form field is not displaying with the way I am doing it below...

       

      <cfset variables.form_field["dateFiled"] = '<cfinput name="test" type="text" value="">'>

       

      <cfform action="test.cfm" name="goForth" method="post">
      #variables.form_field["dateFiled"]#

      </cfform>

        • 1. Re: Dynamic CFML form elements
          Adam Cameron. Level 5

          You can't OUTPUT CFML code and expect it to execute!

           

          CFML needs to be compiled before it will execute.  OUTPUTing something (which even then is outputting not executing) occurs at runtime.

           

          --

          Adam

          • 2. Re: Dynamic CFML form elements
            dujsu Level 1

            You can see what I am trying to do here, do you have any suggestions?

             

            Message was edited by: BigFeetBigShoes - Reworded my response.

            • 3. Re: Dynamic CFML form elements
              Adam Cameron. Level 5

              Well... OK...as an exercise, work through what it is I said.

               

              For the code to compile, it needs to be in the file at compile time.  So you cannot use variables to "create" the code (variables only exist at runtime).  The code needs to already be in the file when it's compiled.

               

              So don't use a variable... use actual code.

               

              So not this:

               

              <cfset variables.form_field["dateFiled"] = '<cfinput name="test" type="text" value="">'>

               

              <cfform action="test.cfm" name="goForth" method="post">
              #variables.form_field["dateFiled"]#

              </cfform>

               

              But this:

               

              <cfform action="test.cfm" name="goForth" method="post">
              <cfinput name="test" type="text" value="">

              </cfform>

               

              That is the trick to getting a CFINPUT to work: the code needs to actually be there at compile time.  Which is what you asked.

               

              If you want to write code dynamically (which you mention in your heading, but not in your actual post), you need to write it to file, then execute the file (browse to it, CFHTTP it, CFINCLUDE it, etc).

               

              This is not a great way to go about things though.

               

              To come up with a good way, you're going to have to define your requirements a bit more thoroughly.  Otherwise all you're going to get is answers to the questions you actually ask.  Which you didn't seem to react to very well.

               

              --

              Adam

              1 person found this helpful
              • 4. Re: Dynamic CFML form elements
                Dave Watts Adobe Community Professional

                The only way you can execute CFML tags are to save them in a file, then CFINCLUDE the file. That probably won't perform all that well, though, so you might rethink what you're trying to do - which is what Adam is suggesting. For example, do you really need the tag to be data? Or do you just need the name and value of the field to be data?

                 

                Dave Watts, CTO, Fig Leaf Software

                http://www.figleaf.com/

                http://training.figleaf.com/

                1 person found this helpful
                • 5. Re: Dynamic CFML form elements
                  dujsu Level 1

                  Adam,

                  I believe my question was pretty clear and straight foward. As you mentioned in the subject it states "Dynamic CFML form elements" and you can clearly see that I am not trying to build a static form in my example, which for some reason you thought I was suggesting.

                  Dynamic CFML form elements

                  Is there a trick to getting the cfinput to display? The form field is not displaying with the way I am doing it below...

                   

                  <cfset variables.form_field["dateFiled"] = '<cfinput name="test" type="text" value="">'>

                   

                  <cfform action="test.cfm" name="goForth" method="post">
                  #variables.form_field["dateFiled"]#

                  </cfform>

                   

                  As for how I reacted, Im not a fan of half-assed answers when seeking guidance from those with more experience. So you are right, I did not have a positive reaction to your response.

                  • 6. Re: Dynamic CFML form elements
                    dujsu Level 1

                    Dave,

                     

                    Thanks for the response and the further probing. I think I will just use standard HTML form elements instead of CF form elements.

                     

                    I am doing sort of a mail merge by replacing placeholder text such as "[dateFiled]" or "[formTextarea1]" within an already formatted letter with form elements that the user will be able to fill out. So the form layout will look like a letter, but will have specific editable form elements. The user then submits the form in order to create a final PDF version of the letter.

                     

                    So if I understand what you are asking, my answer is yes, I think I will need the tag to be the data..

                    • 7. Re: Dynamic CFML form elements
                      Dave Watts Adobe Community Professional

                      But none of those examples you gave require the tag to be the data. You could, for example, have database fields that stores the type and name attributes, and have conditional logic to insert the appropriate type of form field and specify the values for type and name.

                       

                      Dave Watts, CTO, Fig Leaf Software

                      http://www.figleaf.com/

                      http://training.figleaf.com/

                      • 8. Re: Dynamic CFML form elements
                        dujsu Level 1

                        Well that would work if I was only using input elements, but Im using more field types such as textarea, select, and fields that tie together with javascript libraries such as ckeditor and jquery's datepicker. Unfortunately we can't use Coldfusion's built in wysiwyg editor or datefield because they are not 508 compliant. But storing the amount of attributes and their values seems to be significantly more work compared to storing the entire form element. And Im just using a structure at the moment for this example, so I will be storing the values into the database once I get this form/letter structure created.

                        • 9. Re: Dynamic CFML form elements
                          dujsu Level 1

                          Dave,

                           

                          After thinking about your suggestion a little more, I think I can see now how storing individual attributes may be better than storing the entire string. Definetly would be more dynamic. There are quite a few attributes within the fields but I think it will work better. Thanks again for the suggestion.