Code
<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>
<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)#">
<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>
<cfform action="update_ldap.cfm"
method="post">
<table>
<tr><td>Full Name:</td>
<td><cfinput type="Text"
name="fullName"
value=#fullNameValue#
size="20"
maxlength="30"
tabindex="1"></td>
</tr>
.
.
.
<tr><td colspan="2">
<input type="Submit"
name="action"
value="Add"
tabindex="6"></td>
</tr>
</table>
<br>
*All fields are required for Add<br>
</cfform>
492
Chapter 23: Managing LDAP Directories
Description
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.
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
function removes leading or trailing
Trim
spaces from the user data.
Adds the new entry to the directory.
Outputs the data entry form, formatted as a table.
Each
field always has a value, set by the
cfinput
attribute when the page is called. The
value
attribute lets ColdFusion update the form contents
when the form is redisplayed after the user clicks
Add. The code that handles cases in which the user
fails to enter all the required data uses this feature.
value
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers