Adobe ColdFusion 8

Updating a directory entry

The cfldap tag lets you change the values of entry attributes. To do so, you specify the entry DN in the dn attribute, and list the attributes to change and their new values in the attributes attribute.

The following example builds on the code that adds and deletes an entry. It can update one or more of an entry's attributes. Because the UID is part of the DN, you cannot change it.

  1. Open update_ldap.cfm, which you created in Adding a directory entry.
  2. Between the cfelseif Form.action is "Retrieve" block and the </cfif> tag, add the following code:
    <cfelseif Form.action is "Update">
    <cfset attributelist="cn=#Trim(form.FullName)#; sn=#Trim(Form.surname)#; mail=#Trim(Form.email)#; 
        telephonenumber=#Trim(Form.phone)#">
    <cfldap action="modify"
        modifytype="replace"
        attributes="#attributeList#"
        dn="uid=#Trim(Form.UID)#, ou=People, o=Airius.com"
        server=#myServer#
        username=#myUserName#
        password=#myPassword#>    
    <cfoutput><h3>Entry for User ID #Form.UID# has been updated</h3>
    </cfoutput>
    

  3. At the end of the code for the Delete button (the input tag with Value=Delete at the bottom of the form), delete the </td> mark.
  4. After the end of the Delete button input tag, add the following code:
    &nbsp
    <input type="Submit"
        name="action"
        value="Update"
    	tabindex="9"></td>
    

  5. Save the file and run it in your browser.

Reviewing the code

The following table describes the code:

Code

Description

<cfelseif Form.action is "Update"> <cfset attributelist="cn=#Trim (form.FullName)#; sn=#Trim(Form.surname)#; mail=#Trim(Form.email)#; telephonenumber=#Trim(Form.phone)#"> <cfldap action="modify" modifytype="replace" attributes="#attributeList#" dn="uid=#Trim(Form.UID)#, ou=People, o=Airius.com" server=#myServer# username=#myUserName# password=#myPassword#> <cfoutput><h3>Entry for User ID #Form.UID# has been updated</h3> </cfoutput>

If the user clicks Update, sets the attribute list to the form field values and replaces the attributes for the entry with the specified UID.

Displays a message to indicate that the entry was updated.

This code replaces all of the attributes in a form, without checking whether they are blank. A more complete example would check for blank fields and either require entered data or not include the corresponding attribute in the attributes string.

&nbsp <input type="Submit" name="action" value="Update" tabindex="9"></td>

Defines the Submit button for the update action.