开发者

Checking for TextField changes once a form was submitted in Coldfusion

开发者 https://www.devze.com 2023-03-10 01:03 出处:网络
I have code that displays database entries, and allows for editing/deletion. I am trying to find some way on submission to see if a particular field has been changed, so if the old data of the field

I have code that displays database entries, and allows for editing/deletion.

I am trying to find some way on submission to see if a particular field has been changed, so if the old data of the field is not referenced by any database entries, I can delete it. Any ideas on how to do this?

To respond to the first comment / Edit: It is somewhat hard to put code of this problem up here, but I will try to grab some snippets that help.

<td>Upload File:</td>
<td>
    <input type="file" name="txtName" size="50" />
</td>
<cfif url.filesid neq "0">
<td>Or Use Server File:</td>
    <td>
    <select name="ddlFilesNames">
        <option value="" selected></option> 
            <cfoutput query="qfiles">
      开发者_如何学运维          <option 
                  value="#qfiles.name#" 
                  #iif(qfiles.name eq recEditFiles.fileName,DE("selected"),DE(""))#
                >#qfiles.name#</option>
            </cfoutput>                         
    </select>
    </td>
</cfif>

These are the two fields I need to check if they changed, when the edit button is hit the select drop down list has the current server file displayed, but during editing they can either add a file to the textfield (through a browse option to upload a new file) or they can select another file from the dropdown list, and then hit an update button that submits the changes.

When the update button is hit I need to somehow check to see if the fields were changed at all.

I feel that one of the main problems is that once the button is hit, a javascript method is called, and so far I have been unsuccessful is lacing coldfusion within javascript methods, everytime I try to do this or visa-versa it breaks the program.


A simple way to compare whether fields on a form have changed from the original is to include the original data in a hidden form field then on the action page compare the values of the form field and its hidden counterpart and see if they've changed.

form:

<input type="text" name="myField" value="#q.myField#" />
<input type="hidden" name="myField_original" value="#q.myField#" />

action:

<cfif form.myField NEQ form.myField_original>
  <cfset fieldHasChanged = true />
<cfelse>
  <cfset fieldHasChanged = false />
</cfif>

If you're consistent with form field names it'll be easy to create a loop on the action page to do these comparisons.


Some code would help. Sounds like you have a <input type="file" ... /> and you want to know if the user "removes" the file from the DB record being entered?

Usually I handle this by showing the current file associated with the record and a "delete" button or icon that allows you to remove that image. I also include a "replace" or "upload new" or "upload another" button that allows the user to select another file to replace the current file, or add a file to a record without a file.

If you don't do something like this, then you have no way of knowing if the user just didn't feel like uploading the same file again (because its already there, why would they?) or if they intended to have your system remove that file and its association with the database record.

0

精彩评论

暂无评论...
验证码 换一张
取 消