XWeb: IndividualFax 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 fax number.
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.cfx_key IS ""){
form.cfx_key = default_key;
}
else {
form.cfx_key = form.cfx_key;
}
if (ISDEFINED("btn_delete")) {
form.cfx_delete_flag = 1;
}
else {
form.cfx_delete_flag = 0;
}
if (ISDEFINED("form.cfx_unlisted_flag")) {
form.cfx_unlisted_flag = 1;
}
else {
form.cfx_unlisted_flag = 0;
}
</cfscript>
<cfsavecontent variable="faxXML">
<cfoutput>
<ns:IndividualFaxObjects>
<ns:IndividualFaxObject>
<ns:fax_number><cfif len(form.fax_number) neq 0>#trim(form.fax_number)#<cfelse></cfif></ns:fax_number>
<ns:cfx_extension><cfif len(form.cfx_extension) neq 0>#trim(form.cfx_extension)#<cfelse></cfif></ns:cfx_extension>
<ns:cfx_fxt_key>#form.cfx_fxt_key#</ns:cfx_fxt_key>
<ns:cfx_delete_flag>#val(form.cfx_delete_flag)#</ns:cfx_delete_flag>
<ns:cfx_unlisted_flag>#val(form.cfx_unlisted_flag)#</ns:cfx_unlisted_flag>
<ns:cfx_change_date>#nfws_change_date#</ns:cfx_change_date>
<ns:cfx_change_user>#nfws_change_user#</ns:cfx_change_user>
</ns:IndividualFaxObject>
</ns:IndividualFaxObjects>
</cfoutput>
</cfsavecontent>
<cfinvoke component="/gateway/netforum_xweb" method="xweb_UpdateFacadeObject" returnvariable="nfws_result_fax">
<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="IndividualFax" omit="no">
<cfinvokeargument name="szObjectKey" value="#trim(form.cfx_key)#" omit="no">
<cfinvokeargument name="oNode" value="#trim(faxXML)#" 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_cfx_key>#form.cst_cfx_key#</ns:cst_cfx_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.cfx_key = form.cfx_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 - IndividualFax --->
<cftry>
<cfparam name="url.cfx_key" default="#default_key#">
<cfinvoke component="/gateway/netforum_xweb" method="xweb_GetFacadeObject" returnvariable="qryIndividualFax">
<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="IndividualFax" omit="no">
<cfinvokeargument name="szObjectKey" value="#url.cfx_key#" omit="no">
</cfinvoke>
<cfquery name="qryGetFaxCategories" datasource="#nfdatabase#">
SELECT fxt_key,
fxt_code
FROM co_fax_type (nolock)
WHERE fxt_key NOT IN
(
SELECT cfx_fxt_key
FROM co_customer_x_fax
WHERE cfx_cst_key = '#session.cst_key#'
AND cfx_delete_flag = 0
)
AND fxt_delete_flag = 0
ORDER BY fxt_code
</cfquery>
<cfcatch type="any">
<cfscript>
qryIndividualFax = QueryNew("cfx_key");
newRow = QueryAddRow(qryIndividualFax,1);
temp = QuerySetCell(qryIndividualFax, "cfx_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="qryIndividualFax">
<cfquery name="qryGetFaxCategory" datasource="#nfdatabase#">
SELECT fxt_key,
fxt_code
FROM co_fax_type (nolock)
WHERE fxt_key = '#cfx_fxt_key#'
AND fxt_delete_flag = 0
</cfquery>
<strong>#cst_name_cp#</strong>:<br />
<br />
<table>
<tr><td valign="top" colspan="2">
Fax Number: <cfif cst_cfx_key IS "#cfx_key#"><small><em>(primary)</em></small></cfif><br />
<cfinput type="text" name="fax_number" value="#fax_number#" size="30" validate="telephone" required="yes" message="An fax number is required."><br />
</td><td valign="top">
Type:<br />
<cfselect name="cfx_fxt_key">
<cfloop query="qryGetFaxCategory">
<option value="#fxt_key#" selected="selected">#fxt_code#</option>
<option value="">-- or select another --</option>
</cfloop>
<cfloop query="qryGetFaxCategories">
<option value="#fxt_key#">#fxt_code#</option>
</cfloop>
</cfselect>
</td></tr>
<tr><td valign="top">
Extension:<br />
<cfinput type="text" name="cfx_extension" value="#cfx_extension#" size="5"><br />
</td><td valign="top">
Unlisted:<br />
<cfinput type="checkbox" name="cfx_unlisted_flag" value="1" checked="#val(cfx_unlisted_flag)#"><br />
</td><td valign="top">
Primary:<br />
<script language="javascript" type="text/javascript">
function togglePrimary() {
if (document.upd.cst_cfx_key_trigger.checked == true) {
document.upd.cst_cfx_key.value='#cfx_key#';
}
if (document.upd.cst_cfx_key_trigger.checked == false) {
document.upd.cst_cfx_key.value='#cst_cfx_key#';
}
}
</script>
<cfif cst_cfx_key EQ cfx_key>
<cfset isChecked=1>
<cfelse>
<cfset isChecked=0>
</cfif>
<cfinput type="checkbox" name="cst_cfx_key_trigger" value="#cfx_key#" checked="#isChecked#" onclick="togglePrimary();"><br />
<cfinput type="hidden" name="cst_cfx_key" value="#cst_cfx_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="cfx_key" value="#trim(cfx_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>