Passing values with a hidden CFInput

4.5k Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

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)

1
On

Others have provide your answer. My answer is just advice about your form.

Your hidden cfinputs shouldn't be in a table. Tables are for displayed items. You'd be much better served to move your hidden cfinputs right under your cfform tag, like this:

<cfform name="update" method="post">
// NON DISPLAY STUFF
<cfinput name="oldUsername" value="#username#" type="hidden">
<cfinput name="oldEmail" value="#email#" type="hidden">
<cfinput name="oldSecurityID" value="#securityID#" type="hidden">
// DISPLAY STUFF
<table>
</table>
</cfform>