XWeb: IndividualPhone 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 phone 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.cph_key IS ""){
form.cph_key = default_key;
}
else {
form.cph_key = form.cph_key;
}
if (ISDEFINED("btn_delete")) {
form.cph_delete_flag = 1;
}
else {
form.cph_delete_flag = 0;
}
if (ISDEFINED("form.cph_unlisted_flag")) {
form.cph_unlisted_flag = 1;
}
else {
form.cph_unlisted_flag = 0;
}
</cfscript>
<cfsavecontent variable="phnXML">
<cfoutput>
<ns:IndividualPhoneObjects>
<ns:IndividualPhoneObject>
<ns:phn_number><cfif len(form.phn_number) neq 0>#trim(form.phn_number)#<cfelse></cfif></ns:phn_number>
<ns:cph_extension><cfif len(form.cph_extension) neq 0>#trim(form.cph_extension)#<cfelse></cfif></ns:cph_extension>
<ns:cph_pht_key>#form.cph_pht_key#</ns:cph_pht_key>
<ns:cph_delete_flag>#val(form.cph_delete_flag)#</ns:cph_delete_flag>
<ns:cph_unlisted_flag>#val(form.cph_unlisted_flag)#</ns:cph_unlisted_flag>
<ns:cph_change_date>#nfws_change_date#</ns:cph_change_date>
<ns:cph_change_user>#nfws_change_user#</ns:cph_change_user>
</ns:IndividualPhoneObject>
</ns:IndividualPhoneObjects>
</cfoutput>
</cfsavecontent>
<cfinvoke component="/gateway/netforum_xweb" method="xweb_UpdateFacadeObject" returnvariable="nfws_result_phn">
<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="IndividualPhone" omit="no">
<cfinvokeargument name="szObjectKey" value="#trim(form.cph_key)#" omit="no">
<cfinvokeargument name="oNode" value="#trim(phnXML)#" 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_cph_key>#form.cst_cph_key#</ns:cst_cph_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.cph_key = form.cph_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.cph_key" default="#default_key#">
<cfinvoke component="/gateway/netforum_xweb" method="xweb_GetFacadeObject" returnvariable="qryIndividualPhone">
<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="IndividualPhone" omit="no">
<cfinvokeargument name="szObjectKey" value="#url.cph_key#" omit="no">
</cfinvoke>
<cfquery name="qryGetPhoneCategories" datasource="#nfdatabase#">
SELECT pht_key,
pht_code
FROM co_phone_type (nolock)
WHERE pht_key NOT IN
(
SELECT cph_pht_key
FROM co_customer_x_phone
WHERE cph_cst_key = '#session.cst_key#'
AND cph_delete_flag = 0
)
AND pht_delete_flag = 0
ORDER BY pht_code
</cfquery>
<cfcatch type="any">
<cfscript>
qryIndividualPhone = QueryNew("cph_key");
newRow = QueryAddRow(qryIndividualPhone,1);
temp = QuerySetCell(qryIndividualPhone, "cph_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="qryIndividualPhone">
<cfquery name="qryGetPhoneCategory" datasource="#nfdatabase#">
SELECT pht_key,
pht_code
FROM co_phone_type (nolock)
WHERE pht_key = '#cph_pht_key#'
AND pht_delete_flag = 0
</cfquery>
<strong>#cst_name_cp#</strong>:<br />
<br />
<table>
<tr><td valign="top" colspan="2">
Phone Number: <cfif cst_cph_key IS "#cph_key#"><small><em>(primary)</em></small></cfif><br />
<cfinput type="text" name="phn_number" value="#phn_number#" size="30" validate="telephone" required="yes" message="An phone number is required."><br />
</td><td valign="top">
Type:<br />
<cfselect name="cph_pht_key">
<cfloop query="qryGetPhoneCategory">
<option value="#pht_key#" selected="selected">#pht_code#</option>
<option value="">-- or select another --</option>
</cfloop>
<cfloop query="qryGetPhoneCategories">
<option value="#pht_key#">#pht_code#</option>
</cfloop>
</cfselect>
</td></tr>
<tr><td valign="top">
Extension:<br />
<cfinput type="text" name="cph_extension" value="#cph_extension#" size="5"><br />
</td><td valign="top">
Unlisted:<br />
<cfinput type="checkbox" name="cph_unlisted_flag" value="1" checked="#val(cph_unlisted_flag)#"><br />
</td><td valign="top">
Primary:<br />
<script language="javascript" type="text/javascript">
function togglePrimary() {
if (document.upd.cst_cph_key_trigger.checked == true) {
document.upd.cst_cph_key.value='#cph_key#';
}
if (document.upd.cst_cph_key_trigger.checked == false) {
document.upd.cst_cph_key.value='#cst_cph_key#';
}
}
</script>
<cfif cst_cph_key EQ cph_key>
<cfset isChecked=1>
<cfelse>
<cfset isChecked=0>
</cfif>
<cfinput type="checkbox" name="cst_cph_key_trigger" value="#cph_key#" checked="#isChecked#" onclick="togglePrimary();"><br />
<cfinput type="hidden" name="cst_cph_key" value="#cst_cph_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="cph_key" value="#trim(cph_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>