XWeb: IndividualAddress 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's 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 individual's address information.
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.
The Individual Address form has a couple drop down dependencies. The code below assumes there are two queries defined in the application scope: qrySelectState and qrySelectCountry.
Sample Code
<!--- Process Update --->
<cfif ISDEFINED("form.btn_update") OR ISDEFINED("form.btn_delete")>
<cfscript>
// fix null key
if (form.cxa_key IS ""){
form.cxa_key = default_key;
}
else {
form.cxa_key = form.cxa_key;
}
if (ISDEFINED("btn_delete")) {
form.cxa_delete_flag = 1;
}
else {
form.cxa_delete_flag = 0;
}
</cfscript>
<cfsavecontent variable="adrXML">
<cfoutput>
<ns:IndividualAddressObjects>
<ns:IndividualAddressObject>
<ns:adr_line1>#trim(form.adr_line1)#</ns:adr_line1>
<ns:adr_line2>#trim(form.adr_line2)#</ns:adr_line2>
<ns:adr_line3>#trim(form.adr_line3)#</ns:adr_line3>
<ns:adr_city>#trim(form.adr_city)#</ns:adr_city>
<ns:adr_state>#trim(form.adr_state)#</ns:adr_state>
<ns:adr_post_code>#trim(form.adr_post_code)#</ns:adr_post_code>
<ns:adr_county>#trim(form.adr_county)#</ns:adr_county>
<ns:adr_latitude>#trim(form.adr_latitude)#</ns:adr_latitude>
<ns:adr_longitude>#trim(form.adr_longitude)#</ns:adr_longitude>
<ns:adr_change_date>#nfws_change_date#</ns:adr_change_date>
<ns:adr_change_user>#nfws_change_user#</ns:adr_change_user>
<ns:cxa_delete_flag>#form.cxa_delete_flag#</ns:cxa_delete_flag>
<ns:cxa_adt_key>#form.cxa_adt_key#</ns:cxa_adt_key>
<ns:cst_cxa_key>#form.cst_cxa_key#</ns:cst_cxa_key>
</ns:IndividualAddressObject>
</ns:IndividualAddressObjects>
</cfoutput>
</cfsavecontent>
<cfinvoke component="/gateway/netforum_xweb" method="xweb_UpdateFacadeObject" returnvariable="nfws_result_adr">
<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="IndividualAddress" omit="no">
<cfinvokeargument name="szObjectKey" value="#trim(form.cxa_key)#" omit="no">
<cfinvokeargument name="oNode" value="#trim(adrXML)#" 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_cxa_key>#form.cst_cxa_key#</ns:cst_cxa_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.cxa_key = form.cxa_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_Authenticate : Initialize --->
<cftry>
<cfinvoke component="/gateway/netforum_xweb" method="xweb_Authenticate" returnvariable="nfws_token">
<cfinvokeargument name="uname" value="#application.nfws_uname#" omit="no">
<cfinvokeargument name="pword" value="#application.nfws_pword#" omit="no">
</cfinvoke>
<cfcatch type="any">
<h4>Unable to connect to the web service gateway.</h4>
<cfflush>
<cfabort>
</cfcatch>
</cftry>
<!--- xweb_GetFacadeObject - IndividualAddress --->
<cftry>
<cfparam name="url.cxa_key" default="#default_key#">
<cfinvoke component="/gateway/netforum_xweb" method="xweb_GetFacadeObject" returnvariable="qryIndividualAddress">
<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="IndividualAddress" omit="no">
<cfinvokeargument name="szObjectKey" value="#url.cxa_key#" omit="no">
</cfinvoke>
<cfquery name="qryGetAddressCategories" datasource="#nfdatabase#">
SELECT adt_key,
adt_code
FROM co_address_type (nolock)
WHERE adt_key NOT IN
(
SELECT cxa_adt_key
FROM co_customer_x_address
WHERE cxa_cst_key = '#session.cst_key#'
AND cxa_delete_flag = 0
)
AND adt_delete_flag = 0
ORDER BY adt_code
</cfquery>
<cfcatch type="any">
<cfscript>
qryIndividualAddress = QueryNew("cxa_key");
newRow = QueryAddRow(qryIndividualAddress,1);
temp = QuerySetCell(qryIndividualAddress, "cxa_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="qryIndividualAddress">
<cfquery name="qryGetAddressCategory" datasource="#nfdatabase#">
SELECT adt_key,
adt_code
FROM co_address_type (nolock)
WHERE adt_key = '#cxa_adt_key#'
AND adt_delete_flag = 0
</cfquery>
<strong>#cst_name_cp#</strong>:<br />
<br />
<div style="margin:0px; padding:10px; border:1px black solid;">
<table>
<tr><td colspan="3">
Address Line 1:<br />
<cfinput type="text" name="adr_line1" value="#adr_line1#" size="50" required="yes" message="Address Line 1 is required"><br />
</td></tr>
<tr><td colspan="3">
Address Line 2:<br />
<cfinput type="text" name="adr_line2" value="#adr_line2#" size="50" required="no"><br />
</td></tr>
<tr><td colspan="3">
Address Line 3:<br />
<cfinput type="text" name="adr_line3" value="#adr_line3#" size="50" required="no"><br />
</td></tr>
<tr><td valign="top">
City:<br />
<cfinput type="text" name="adr_city" value="#adr_city#" size="50" required="yes" message="City is required"><br />
</td><td valign="top">
State:<br />
<cfselect id="adr_state" name="adr_state">
<cfparam name="statefieldname" default="state">
<option value="">- select one -</option>
<cfloop query="application.qrySelectState">
<cfif trim(value) IS NOT "">
<option value="#value#"<cfif qryIndividualAddress.adr_state IS "#value#"> selected="selected"</cfif>>#display#</option>
</cfif>
</cfloop>
</cfselect><br />
</td><td valign="top">
Post Code:<br />
<cfinput type="text" name="adr_post_code" value="#adr_post_code#" size="15" required="yes" message="Post Code is required"><br />
</td></tr>
<tr><td valign="top">
County:<br />
<cfinput type="text" name="adr_county" value="#adr_county#" size="30" required="no"><br />
</td><td colspan="3" valign="top">
Country:<br />
<cfselect id="adr_country" name="adr_country" disabled="disabled">
<cfparam name="countryfieldname" default="country">
<option value="United States">United States</option>
<option value="">- select one -</option>
<cfloop query="application.qrySelectCountry">
<cfif trim(value) IS NOT "">
<option value="#value#"<cfif qryIndividualAddress.adr_country IS "#value#"> selected="selected"</cfif>>#display#</option>
</cfif>
</cfloop>
</cfselect><br />
</td></tr>
</table>
<table>
<tr><td valign="top">
Laitude:<br />
<cfinput type="text" name="adr_latitude" value="#adr_latitude#" size="25"><br />
</td><td valign="top">
Longitude:<br />
<cfinput type="text" name="adr_longitude" value="#adr_longitude#" size="25"><br />
</td><td>
Type:<br />
<cfselect name="cxa_adt_key">
<cfloop query="qryGetAddressCategory">
<option value="#adt_key#" selected="selected">#adt_code#</option>
<option value="">-- or select another --</option>
</cfloop>
<cfloop query="qryGetAddressCategories">
<option value="#adt_key#">#adt_code#</option>
</cfloop>
</cfselect><br />
</td><td valign="top">
Primary:<br />
<script language="javascript" type="text/javascript">
function togglePrimary() {
if (document.upd.cst_cxa_key_trigger.checked == true) {
document.upd.cst_cxa_key.value='#cxa_key#';
}
if (document.upd.cst_cxa_key_trigger.checked == false) {
document.upd.cst_cxa_key.value='#cst_cxa_key#';
}
}
</script>
<cfif cst_cxa_key EQ cxa_key>
<cfset isChecked=1>
<cfelse>
<cfset isChecked=0>
</cfif>
<cfinput type="checkbox" name="cst_cxa_key_trigger" value="#cxa_key#" checked="#isChecked#" onclick="togglePrimary();"><br />
<cfinput type="hidden" name="cst_cxa_key" value="#cst_cxa_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="cxa_key" value="#trim(cxa_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>