XWeb: IndividualEmail HTML Form Edit ColdFusion Sample 1
ColdFusion makes it very easy to integrate with web services. One of the most common requirements an organization has is the need to insert and update a variety of member information. Most often, this includes individual addresses, phone numbers, fax numbers, and e-mail addresses.
The code provided below is an example of how HTML, ColdFusion, and xWeb can be used to edit an e-mail address.
Assumptions
In order to use the code provided below, you will need to have successfully implemented the various web methods using the required core ColdFusion component for xWeb.
Sample Code
<!--- Process Update --->
<cfif ISDEFINED("form.btn_update") OR ISDEFINED("form.btn_delete")>
<cfscript>
// fix null key
if (form.eml_key IS ""){
form.eml_key = default_key;
}
else {
form.eml_key = form.eml_key;
}
if (ISDEFINED("btn_delete")) {
form.eml_delete_flag = 1;
}
else {
form.eml_delete_flag = 0;
}
</cfscript>
<cfsavecontent variable="emlXML">
<cfoutput>
<ns:IndividualEmailObjects>
<ns:IndividualEmailObject>
<ns:eml_address><cfif len(form.eml_address) NEQ 0>#trim(form.eml_address)#<cfelse></cfif></ns:eml_address>
<ns:eml_type><cfif len(form.eml_type) NEQ 0>#trim(form.eml_type)#<cfelse></cfif></ns:eml_type>
<ns:eml_delete_flag>#val(form.eml_delete_flag)#</ns:eml_delete_flag>
<ns:eml_change_date>#nfws_change_date#</ns:eml_change_date>
<ns:eml_change_user>#nfws_change_user#</ns:eml_change_user>
</ns:IndividualEmailObject>
</ns:IndividualEmailObjects>
</cfoutput>
</cfsavecontent>
<cfinvoke component="/gateway/netforum_xweb" method="xweb_UpdateFacadeObject" returnvariable="nfws_result_eml">
<cfinvokeargument name="nfws_namespace" value="#application.nfws_namespace#" omit="no">
<cfinvokeargument name="nfws_address" value="#application.nfws_address#" omit="no">
<cfinvokeargument name="nfws_token" value="#session.nfws_token#" omit="no">
<cfinvokeargument name="szObjectName" value="IndividualEmail" omit="no">
<cfinvokeargument name="szObjectKey" value="#trim(form.eml_key)#" omit="no">
<cfinvokeargument name="oNode" value="#trim(emlXML)#" omit="no">
</cfinvoke>
<cfsavecontent variable="cstXML">
<cfoutput>
<ns:IndividualObjects>
<ns:IndividualObject>
<ns:cst_change_date>#nfws_change_date#</ns:cst_change_date>
<ns:cst_change_user>#nfws_change_user#</ns:cst_change_user>
<ns:cst_eml_key>#form.cst_eml_key#</ns:cst_eml_key>
</ns:IndividualObject>
</ns:IndividualObjects>
</cfoutput>
</cfsavecontent>
<cfinvoke component="/gateway/netforum_xweb" method="xweb_UpdateFacadeObject" returnvariable="nfws_result_cst">
<cfinvokeargument name="nfws_namespace" value="#application.nfws_namespace#" omit="no">
<cfinvokeargument name="nfws_address" value="#application.nfws_address#" omit="no">
<cfinvokeargument name="nfws_token" value="#session.nfws_token#" omit="no">
<cfinvokeargument name="szObjectName" value="Individual" omit="no">
<cfinvokeargument name="szObjectKey" value="#trim(form.cst_key)#" omit="no">
<cfinvokeargument name="oNode" value="#trim(cstXML)#" omit="no">
</cfinvoke>
<cfset url.eml_key = form.eml_key>
<script language="javascript" type="text/javascript">
alert('Update Successful.\nClick OK to continue.');
</script>
<script language="javascript" type="text/javascript">
var oParent = window.opener;
oParent.location.reload();
window.close();
</script>
<cfabort>
<cfflush>
</cfif>
<!--- xweb_GetFacadeObject - IndividualEmail --->
<cftry>
<cfparam name="url.eml_key" default="#default_key#">
<cfinvoke component="/gateway/netforum_xweb" method="xweb_GetFacadeObject" returnvariable="qryIndividualEmail">
<cfinvokeargument name="nfws_namespace" value="#application.nfws_namespace#" omit="no">
<cfinvokeargument name="nfws_address" value="#application.nfws_address#" omit="no">
<cfinvokeargument name="nfws_token" value="#session.nfws_token#" omit="no">
<cfinvokeargument name="szObjectName" value="IndividualEmail" omit="no">
<cfinvokeargument name="szObjectKey" value="#url.eml_key#" omit="no">
</cfinvoke>
<cfquery name="qryGetEmailCategories" datasource="#nfdatabase#">
SELECT DISTINCT eml_type
FROM co_email (nolock)
WHERE eml_type NOT IN (
SELECT eml_type
FROM co_email (nolock)
WHERE eml_cst_key='#session.cst_key#'
AND eml_delete_flag = 0
)
AND eml_delete_flag = 0
ORDER BY eml_type
</cfquery>
<cfcatch type="any">
<cfscript>
qryIndividualEmail = QueryNew("eml_key");
newRow = QueryAddRow(qryIndividualEmail,1);
temp = QuerySetCell(qryIndividualEmail, "eml_key", "", 1);
</cfscript>
</cfcatch>
</cftry>
<!--- Display Form --->
<div style="width:600px; background-color:white;">
<br />
<cfform action="#cgi.script_name#" method="post" name="upd" id="upd">
<cfoutput query="qryIndividualEmail">
<strong>#cst_sort_name_dn#</strong>:<br />
<br />
<table>
<tr><td valign="top">
Address: <cfif cst_eml_key IS "#eml_key#"><small><em>(primary)</em></small></cfif><br />
<cfinput type="text" name="eml_address" value="#eml_address#" size="35" validate="email" required="yes" message="An e-mail address is required."><br />
</td><td valign="top">
Type:<br />
<cfselect name="eml_type">
<option value="#eml_type#" selected="selected">#eml_type#</option>
<option value="">-- or select another --</option>
<cfloop query="qryGetEmailCategories">
<option value="#eml_type#">#eml_type#</option>
</cfloop>
</cfselect>
</td><td valign="top">
Primary:<br />
<script language="javascript" type="text/javascript">
function togglePrimary() {
if (document.upd.cst_eml_key_trigger.checked == true) {
document.upd.cst_eml_key.value='#eml_key#';
}
if (document.upd.cst_eml_key_trigger.checked == false) {
document.upd.cst_eml_key.value='#cst_eml_key#';
}
}
</script>
<cfif cst_eml_key EQ eml_key>
<cfset isChecked=1>
<cfelse>
<cfset isChecked=0>
</cfif>
<cfinput type="checkbox" name="cst_eml_key_trigger" value="#eml_key#" checked="#isChecked#" onclick="togglePrimary();"><br />
<cfinput type="hidden" name="cst_eml_key" value="#cst_eml_key#">
</td></tr>
</table>
<br />
<table width="100%">
<tr><td align="right">
<cfinput type="hidden" name="cst_key" value="#trim(cst_key)#" />
<cfinput type="hidden" name="eml_key" value="#trim(eml_key)#" />
<cfinput type="submit" name="btn_update" value="UPDATE" />
<cfinput type="submit" name="btn_delete" value="DELETE" />
<cfinput type="reset" name="btn_reset" value="RESET" />
<cfinput type="button" name="btn_close" value="CLOSE" onclick="var oParent = window.opener; oParent.location.reload(); window.close();" />
</td></tr>
</table>
</cfoutput>
<br />
</cfform>
</div>