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

Creating form element from within a component

Participant ,
Dec 04, 2008 Dec 04, 2008

Copy link to clipboard

Copied

Hi all,

I am trying to create a form element within a component function which is then called from a .cfm page which has the cfform tags. I keep getting a context validation error for the form element tag. Here is some sample code:

<cfcomponent name="yourComponent">
<cffunction name="createTag" returntype="string" access="public">

<cfsavecontent variable="returnContent">
<cfselect name="thisSelect">
<option value="0">Value 1</option>
</cfselect>
</cfsaveconten>

<cfreturn returnContent>
</cffunction>
</cfcomponent>


And in the .cfm page:

<cfform>
<cfinvoke component="yourComponent" method="createTag" returnVariable="returnContent"/>
<cfoutput>#returnContent#</cfoutput>
</cfform>

The error occurs in the function and it says the cfselect must be within a cfform. I tried the function without the save content and just set the output="yes" but the same error occurs.

Any help appreciated in how to get around this. Just putting the code in the .cfm is not an option for this.

Any help appreciated.
Jim
TOPICS
Advanced techniques

Views

581

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 ,
Dec 04, 2008 Dec 04, 2008

Copy link to clipboard

Copied

I can't see any reason why it wouldn't work. What happens if you put that cfcontent stuff inside your .cfm file? This would be for troubleshooting purposes only.

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
Participant ,
Dec 04, 2008 Dec 04, 2008

Copy link to clipboard

Copied

Thanks for the reply. Yes, that works. So it looks like it has to do with the function call.

After some further investigation, I found out that a regular <select> works, it's just the <cfselect> that does not. ColdFusion wants it directly within the <cfform> tag.

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 ,
Dec 04, 2008 Dec 04, 2008

Copy link to clipboard

Copied

quote:

Originally posted by: jim1234
Thanks for the reply. Yes, that works. So it looks like it has to do with the function call.

After some further investigation, I found out that a regular <select> works, it's just the <cfselect> that does not. ColdFusion wants it directly within the <cfform> tag.

Something does not make sense. If the cfsavecontent worked in the cfm file, there is no reason for it not to work in a cfc.

If you want to persue this, the next troubleshooting step is to copy the function to your cfm file and see if it works. I suspect that you are trying something simple as a proof of concept.

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 ,
Dec 04, 2008 Dec 04, 2008

Copy link to clipboard

Copied

i see the same behaviour.
even with <cfsavecontent><cfselect ...>...</cfselect></cfsavecontent> in
the same .cfm page as the form (but outside the <cfform> tag), it still
throws the "Context validation error for tag cfselect. The tag must be
nested inside a cfform tag." error.

not sure if it is a bug or expected behaviour - will have to check the
documentation...

for a work-around, you can have the actual <cfselect> tag inside
<cfform> and just return <option> tags from you cfc...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.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
Participant ,
Dec 05, 2008 Dec 05, 2008

Copy link to clipboard

Copied

LATEST
Thanks for the confirmation.

When I looked at the documentation, it didn't say anything about not being able to put the cf type form elements in functions, but maybe you'll find something. It just seems like the cf form elements should behave the same in this case as the regular html form elements.

It looks as if ColdFusion is not waiting for the final page rendering to validate the context of the tags and rather is just taking what it can see within the function.

I'll see if anyone else finds anything, and if not, I'll report it as a bug, even though it doesn't help me right now.

Thanks,
Jim

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