I have a simple form. Values are loaded from a database into an array and then the entire table is displayed using cfinput and cfselect tags to allow field editing. So, I was hoping to be able to change any fields up and down the table that is displayed and then click SUBMIT and display the changed fields but nothing is ever changed. The table just reverts back to the original and the changes to the tags dissappear. I don't want to have the user update each field seperately using a seperate form. I would like to have the entire page update in one submission.
Any suggestions:
<!--- **** LOAD ARRAY FROM DATABASE ********************************** --->
<cfset AssignArray = ArrayNew(2)>
<cfset i=1>
<cfoutput query="getAssignments">
<cfset AssignArray[i][1]="#getAssignments.Assignment#">
<cfset AssignArray[i][2]="#getAssignments.Baylor#">
<cfset i = i + 1>
</cfoutput>
<!--- **** FORM WITH TABLE OF VALUES TO CHANGE ********************************** --->
<table border="0" cellspacing="0">
<caption>Update Assignments</caption>
<cfform name="formData">
<table>
<tr><th>#</th><th>Assignment</th><th>Name</th></tr>
<cfloop from="1" to= "#getAssignments.RecordCount#" index="i">
<tr>
<td class="centercell"><cfoutput>#i#</cfoutput></td>
<td><cfinput class="assignSize" type="text" name="Assignment"
maxlength="70"
value="#AssignArray[i][1]#"></td>
<td><cfselect class="assignFont" name="Name" query="getNames"
display="Name" value="Baylor" selected="#TRIM(AssignArray[i][2])#">
<cfif AssignArray[i][2] neq "">
<option value="">Not Assigned</option>
<cfelse>
<option value="" selected="selected" >Not Assigned</option>
</cfif>
</cfselect>
</td>
</tr>
</cfloop>
</table>
<cfinput class="btnStyle" type="submit" name="submit" value="Update">
</cfform>
<!--- ****DUMP FORM WITH CHANGED VALUES ************************************ --->
<cfif IsDefined ("form.Assignment")>
<cfif IsDefined ("form.submit")>
<table>
<tr><th>#</th><th>Assignment</th><th>Name</th></tr>
<cfloop from="1" to= "#getAssignments.RecordCount#" index="i">
<tr>
<td class="centercell"><cfoutput>#i#</cfoutput></td>
<td><cfoutput>#AssignArray[i][1]#</cfoutput></td>
<td><cfoutput>#AssignArray[i][2]#</cfoutput></td>
</tr>
</cfloop>
</table>
</cfif>
</cfif>
You need not copy your query into an array? Just use
Then you can compare directly as in
<cfif len(trim(getAssignments.assignment)) GT 0>
or whatever you need to do to make it make sense to you.I would also avoid the use of
<CFFORM>...
it's generally and universally despised by most of us CF folks. A form will work great. use jquery if you want extra special effects.In the case above if you want to see what is selected it will be located in the form scope. In other words
The name of your select box is "name" which is confusing. Call it something easier to get at like "schoolName".
Wallace - ok I understand what you are trying to do but you need a few things. First you need some javascript (probably) to track your changes. Second you need to "name" your form elements with something unique. You'll be submitting a form with names like "assignment_#schoolid#".
It's what you are trying to do with your #currentrow# variable - but that's not tenable because it's disconnected from the DB and will eventually screw up your data. Your example is probably going to need to be scrapped and started over. This link might help.
http://www.coldfusionmuse.com/index.cfm/2011/1/5/form.loop.update.dataset