|
Deleting a directory entry
To
delete a directory entry,specify the entry DN.
The following example builds on the code that adds an entry.
It adds Retrieve and Delete buttons. The Retrieve button lets you
view a user’s information in the form before you delete it.
Open update_ldap.cfm, which you created
in Adding a directory entry.
Between the first and second cfif tags, add the following
code:
<cfelseif Form.action is "Retrieve">
<cfldap name="GetEntry"
server=#myServer#
action="query"
attributes="cn,sn,mail,telephonenumber,uid"
scope="subtree"
filter="uid=#Trim(Form.UID)#"
start="o=Airius.com">
<cfset fullNameValue = GetEntry.cn[1]>
<cfset surnameValue = GetEntry.sn[1]>
<cfset emailValue = GetEntry.mail[1]>
<cfset phoneValue = GetEntry.telephonenumber[1]>
<cfset uidValue = GetEntry.uid[1]>
<cfelseif Form.action is "Delete">
<cfldap action="delete"
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 deleted
</h3></cfoutput>
At the end of the code for the Add button (the input tag
with Value=Add at the bottom of the form),
delete the </td> end tag.
After the end of the Add button input tag,
add the following code:
 
<input type="Submit"
name="action"
value="Retrieve"
tabindex="7">
 
<input type="Submit"
name="action"
value="Delete"
tabindex="8"></td>
Save the file and run it in your browser.
Reviewing the codeThe following table describes the code:
Code
|
Description
|
<cfelseif Form.action is "Retrieve">
<cfldap name="GetEntry"
server=#myServer#
action="query"
attributes="cn,sn,mail,telephonenumber,uid"
scope="subtree"
filter="uid=#Trim(Form.UID)#"
start="o=Airius.com">
<cfset fullNameValue = GetEntry.cn[1]>
<cfset surnameValue = GetEntry.sn[1]>
<cfset emailValue = GetEntry.mail[1]>
<cfset phoneValue = GetEntry.telephonenumber[1]>
<cfset uidValue = GetEntry.uid[1]>
|
If the user clicks Retrieve, queries the
directory and gets the information for the specified User ID.
Sets
the form field’s Value attribute to the corresponding
query column.
This example uses the array index [1] to identify
the first row of the GetEntry query object. Because the query always
returns only one row, the index can be omitted.
|
<cfelseif Form.action is "Delete">
<cfldap action="delete"
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 deleted
</h3>
|
The user clicks delete, deletes the entry
with the specified User ID, and informs the user that the entry
was deleted.
|
 
<input type="Submit"
name="action"
value="Retrieve"
tabindex="7">
 
<input type="Submit"
name="action"
value="Delete"
tabindex="8"></td>
|
Displays submit buttons for the Retrieve
and Delete actions.
|
|