Skip to main content
Participant
December 9, 2011
Question

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

  • December 9, 2011
  • 2 replies
  • 1717 views

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

    This topic has been closed for replies.

    2 replies

    12Robots
    Participating Frequently
    December 9, 2011

    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.

    Participant
    December 9, 2011

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

    BKBK
    Community Expert
    Community Expert
    December 9, 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. 

    Participant
    December 9, 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.

    BKBK
    Community Expert
    Community Expert
    December 10, 2011

    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>