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

Dynamic CFML form elements

Guest
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

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>

TOPICS
Advanced techniques

Views

1.3K

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , May 18, 2011 May 18, 2011

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/

Votes

Translate

Translate
LEGEND ,
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Guest
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

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

Message was edited by: BigFeetBigShoes - Reworded my response.

Votes

Translate

Translate

Report

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 ,
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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
Guest
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Community Expert ,
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

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/

Votes

Translate

Translate

Report

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
Guest
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

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..

Votes

Translate

Translate

Report

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
Community Expert ,
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

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/

Votes

Translate

Translate

Report

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
Guest
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

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
Guest
May 18, 2011 May 18, 2011

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

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
Documentation