Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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>
Copy link to clipboard
Copied
Use escaped values?
Brown, 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.
Copy link to clipboard
Copied
We tried using Brown, 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."