
463
DEVELOPING
COLDFUSION 9 APPLICATIONS
Accessing and Using Data
Las
t
upda
te
d 8/5/2010
2
At the top of the file, change the
myServer
,
myUserName
, and
myPassword
variable assignments to values that are
valid for your LDAP server.
3
Save the page as update_ldap.cfm and run it in your browser.
Reviewing the code
The following table describes the code:
Code
Description
<cfset myServer="ldap.myco.com">
<cfset myUserName="cn=Directory Manager">
<cfset myPassword="password">
Initializes the LDAP connection information variables. Uses variables for all
connection information so that any changes have to be made in only one
place.
<cfparam name="fullNameValue" default="">
<cfparam name="surnameValue" default="">
<cfparam name="emailValue" default="">
<cfparam name="phoneValue" default="">
<cfparam name="uidValue" default="">
Sets the default values of empty strings for the form field value variables.
The data entry form uses cfinput fields with
value
attributes so that the
form can be prefilled and so that, if the user submits an incomplete form,
ColdFusion can retain any entered values in the form when it redisplays
the page.
<cfif isdefined("Form.action") AND
Trim(Form.uid) IS NOT "">
Ensures that the user entered a User ID in the form.
<cfif Form.action is "add">
If the user clicks Add, processes the code that follows.
<cfif Trim(Form.fullName) is "" OR
Trim(Form.surname) is ""
OR Trim(Form.email) is "" OR Trim(Form.phone) is
"">
<h2>You must enter a value in every field.</h2>
<cfset fullNameValue=Form.fullName>
<cfset surnameValue=Form.surname>
<cfset emailValue=Form.email>
<cfset phoneValue=Form.phone>
<cfset uidValue=Form.uid>
If any field in the submitted form is blank, display a message and set the
other form fields to display data that the user submitted.
<cfelse>
<cfset attributelist="objectclass=top, person,
organizationalperson, inetOrgPerson;
cn=#Trim(Form.fullName)#;
sn=#Trim(Form.surname)#;
mail=#Trim(Form.email)#;
telephonenumber=#Trim(Form.phone)#; ou=Human
Resources; uid=#Trim(Form.uid)#">
If the user entered data in all fields, sets the attributelist variable to specify
the entry’s attributes, including the object class and the organizational
unit (in this case, Human Resources).
The Trim function removes leading or trailing spaces from the user data.
<cfldap action="add"
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
added</h3>
</cfoutput>
</cfif>
</cfif>
</cfif>
Adds the new entry to the directory.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...