Search code examples
coldfusioncfinput

Passing values with a hidden CFInput


I am trying to make a table with editing capabilities, and I have run into problems trying to associate the old values with the updated ones. My solution was to include a hidden CFInput that passes the old value along side the one to be updated, and then the query is run within a cfc.

<cfform name="update" method="post">
<cfoutput query="allusers">
    <tr>
        <td>#username#</td>
        <td>#email#</td>
        <td>#securityID#</td>
        <td><a href="">DELETE</a></td>
    </tr>
        <td><cfinput name="oldUsername" value="#username#" type="hidden"></cfinput><cfinput name="updateUsername" value="New Value"></cfinput></td>
        <td><cfinput name="oldEmail" value="#email#" type="hidden"></cfinput><cfinput name="updateEmail" value="New Value"></cfinput></td>
        <td><cfinput name="oldSecurityID" value="#securityID#" type="hidden"></cfinput><cfinput name="updateSecurityID" value="New Value"></cfinput></td>
        <td><cfinput name="submit" type="submit"></cfinput>
    <tr>
        <cfdump var="oldUsername">
</cfoutput>

Currently I am not getting any errors, but it does not seem to be passing in the old values. Any tips?


Solution

  • Make sure your CFDUMP is using the hash tags:

    <cfdump var="#oldUserName#"> 
    

    otherwise it won't dump the contents of the variable.

    Second of all, you are asking ColdFusion to evaluate "oldusername" when it hasn't had a chance to set oldusername for you yet. Using a CFINPUT tag, simply rewrites this in the HTML to a regular tag with JavaScript and/or Flash enhancements. So form.oldusername will only be available AFTER the post is executed to the next CF template/url. I also recommend highly that you scope (form., variables. etc...) your variables so things don't get crossed (unless you are carefully aware of the variable scope searching order)