Search code examples
variablescoldfusionsession-variablescoldfusion-10dynamic-variables

Outputting dynamic variables


Why can I not make my textbox show only what the user has entered?

<cfinput
 type="text"
 name="firstname_#Add#"
 value="#form['firstname_#Add#']#"
>

I have also researched and tried changing to

<input
 type="text"
 name="firstname_#Add#"
 value="<cfoutput>#form['firstname_#Add#']#</cfoutput>"
>

 <cfloop index="Add" from="1" to="#session.checkout.quantity.pcount#" step="1">
     <cfset session.checkout.info["firstname_#Add#"]="">
    <cfparam name="form['firstname_#Add#']" default="session.checkout.info.firstname_#Add#">
    </cfloop>
    <cfif structKeyExists(form, "submit")>
     <cfset errors = []>
    <cfif not arrayLen(errors)>
    <cfloop index="Add" from="1" to="#session.checkout.quantity.pcount#" step="1">
    <cfset session.checkout.info["firstname_#Add#"]=form["firstname_#Add#"]>
    </cfloop>

Where am I going wrong? Instead of being blank it is showing the session variable (session.checkout.info.firstname_#Add#") then instead of saving it when the user hits a link back to that page it changes what they have entered back to (session.checkout.info.firstname_#Add#"). Anyone have any ideas?


Solution

  • You're telling that CFPARAM to use the text "session...", not the value of "session...". This should get you what you want:

    <cfparam name="form['firstname_' & Add]" default="#session['checkout.info.firstname_' & Add]#">