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

CFForm won't PreserveData for CFSelect options that contain commas!

New Here ,
Dec 08, 2011 Dec 08, 2011

I have simple CFForm with PreserveData set to Yes. I have a simple CFSelect that's populated by a Query. The PreserveData won't work if my CFSelect Query contains data that has commas in it! Here's the data that PreserveData doesn't like:

McLean, Aaron

Smith, Bob

Baker, Tammy

Does anyone have any suggestions on how to get PreserveDAta to work with data containing commas? It works just fine without commas. PreserveData works with multiselect CFSelects so I can see how CF is getting confused by my data.

Thanks for your time!

-Aaronn

1.6K
Translate
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 ,
Dec 09, 2011 Dec 09, 2011

It works for me. Here is the test I did.

Enter the following data into the respective text fields

McLean, Aaron
Smith, Bob
Baker, Tammy
Brown
James


<cfform action="#cgi.script_name#" <!--- preservedata="yes" --->>
<cfinput name="txt1" type="text" value="test value to be replaced"><br>
<cfinput name="txt2" type="text" value="test value to be replaced"><br>
<cfinput name="txt3" type="text" value="test value to be replaced"><br><br>
<cfinput name="txt4" type="text" value="test value"><br>

<!--- Deliberate repetition of field name, to make ColdFusion submit a comma-delimited value --->
<cfinput name="txt4" type="text" value=" to be replaced"><br><br>
<cfinput name="sbmt" type="submit" value="submit">
</cfform>

case 1: without preservedata attribute


The form fields contain, respectively,

test value to be replaced
test value to be replaced
test value to be replaced
test value
to be replaced

case 2: with preservedata attribute set to "yes"


The form fields contain, respectively,


McLean, Aaron 
Smith, Bob 
Baker, Tammy 
Brown, James
Brown, James

Did you submit your form to the same page containing it (that is, is the action page of your form the form page itself)? That is one of the preconditions for preservedata. 

Translate
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
New Here ,
Dec 09, 2011 Dec 09, 2011

Cfinput doesn't have the bug. CFSelect does. In order to use cfselect PreserveData you have to use a Query for the CFSelect. I'll post some code this afternoon.

Translate
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 ,
Dec 10, 2011 Dec 10, 2011
LATEST

AaronCMcLean wrote:

Cfinput doesn't have the bug. CFSelect does. In order to use cfselect PreserveData you have to use a Query for the CFSelect. I'll post some code this afternoon.

I did the following test. It worked as expected.

<cfset testQuery = QueryNew("id, fullName", "integer, varChar")>

<cfset newRow = QueryAddRow(testQuery, 3)>

<cfset temp = QuerySetCell(testQuery, "id", "1", 1)>

<cfset temp = QuerySetCell(testQuery, "fullName", "McLean, Aaron", 1)>

<cfset temp = QuerySetCell(testQuery, "id", "2", 2)>

<cfset temp = QuerySetCell(testQuery, "fullName", "Smith, Bob", 2)>

<cfset temp = QuerySetCell(testQuery, "id", "3", 3)>

<cfset temp = QuerySetCell(testQuery, "fullName", "Baker, Tammy", 3)>

<cfform action="#CGI.SCRIPT_NAME#" preservedata="yes">

    <cfselect name="fn" query="testQuery" value="id" display="fullName" queryposition="below">

    <option value="">Full Name</option>

    </cfselect>

    <cfinput name="sbmt" type="submit" value="submit">

</cfform>

Translate
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
Advocate ,
Dec 09, 2011 Dec 09, 2011

Use escaped values?

Brown&#44; James

Commas are used in Forms to separate multiple values, so "Baker, Tammy" is probably seen as two values "Baker" and "Tammy", neither of which are contained in the list, so nothing is selected.

Translate
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
New Here ,
Dec 09, 2011 Dec 09, 2011

We tried using Brown&#44; James and that didn't work. Surrounding with single quotes didn't work either.

I agree with your comment, "Commas are used in Forms to separate multiple values, so "Baker, Tammy" is probably seen as two values "Baker" and "Tammy", neither of which are contained in the list, so nothing is selected."

Translate
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