Posts

Showing posts with the label ColdFusion

How to get the list of tasks running in coldfusion server

To get the list of tasks which are running on the server, we can use the following code: <cfobject type="JAVA" action="Create" name="factory" class="coldfusion.server.ServiceFactory"> <cfset ListOfTasks = factory.CronService.listAll()/> <cfloop index="i" from="1" to="#ArrayLen(ListOfTasks)#">     <cfdump var="#ListOfTasks[i]#" /> </cfloop>

Coldfusion Code to disable a button

<cfparam name="form.h1" default="0"> <cfif isdefined('form.h1') AND form.h1 EQ 1>     <cfoutput>The button is disabled when you submitted the form</cfoutput> </cfif> <cfform onsubmit="document.getElementById('s1').disabled = 1;" action="#cgi.SCRIPT_NAME#?#cgi.QUERY_STRING#">     <cfinput type="text" name="t1" id="t1"><br>     <cfinput type="text" name="t2" id="t2">     <cfinput type="hidden" name="h1" id="h1" value="1">     <cfinput type="submit" name="s1" id="s1" value="submit"> </cfform>

hash mismatch error while web service call in ColdFusion

These issue occurs since ColdFusion Hash function returned output and the output from PHP will be different in their case (Lower/upper). So for fixing these issues, we have to convert both of them to the same case. for example, we can use the LCase method of ColdFusion to change the hash output to lowercase before passing it to the web service call <cfset hashvalue_test=Hash(#hashvalue_test#,"MD5")> <cfset hashvalue_test=LCase(hashvalue_test)>

Coldfusion Code to get the mail attachments for unread mails using cfimap

The following code opens a connection 'Conn' using cfimap for the given username and password. Also it fetches the unread emails with attachments.  <cfimap action="open" connection="Conn" server="imap.gmail.com" username="test@gmail.com" password="test" secure="yes" > <cfimap action="getall" connection="Conn" name="Query_getAttachments" folder="Inbox" attachmentpath="#GetTempDirectory()#"  > <cfquery dbtype="query" name="getMailAttachments">       select * from Query_getAttachments       where seen=<cfqueryparam value="no" cfsqltype="cf_sql_varchar">       and ATTACHMENTS is not null </cfquery> <cfdump var="#getMailAttachments#"> also if we want to copy the mail attachment from the Temp folder to our server folder, we can use cffile action="copy" or cffile action

Script to Disable multiple Checkboxes with ColdFusion

<html> <head> <script type="text/javascript"> function toggleGroup(id) {     var group = document.getElementById(id);     var inputs = group.getElementsByTagName("input");     for (var i = 0; i < inputs.length; i++) {         inputs[i].disabled = (inputs[i].disabled) ? false : true;     }     } window.onload = function() { document.getElementById("checkmain").onchange = function() {    toggleGroup("check_grp");    } } </script> </head> <body>  <cfform name="form1" >     <cfinput type="checkbox" name="checkmain" id="checkmain" />Enable/Disable<br />     <p id="check_grp">          <input type="checkbox" /><label for="check1">check 1</label>          <input type="checkbox"  /><label for="check2">check 2</label>          <input type=&q

ColdFusion Script to compare a date value

<cfscript>     function isBetween(compVal, FirstVal, SecondVal)         {             var myRetVal = false;             if(FirstVal LTE SecondVal)                 {                     if(compVal GTE FirstVal AND compVal LTE SecondVal)                     RetVal = true;                 }             else                 {                     if(compVal GTE SecondVal AND compVal LTE FirstVal)                     RetVal = true;                 }                                return RetVal;         } </cfscript> <cfif #isBetween(#DateFormat(10/25/2012,"mm/dd/yyyy")#, #dateFormat(10/20/2012,'mm/dd/yyyy')#,#dateFormat(10/30/2012,'mm/dd/yyyy')# )#>     <cfoutput>The date is between the given values </cfoutput> <cfelse>     <cfoutput>The date is not between the given values </cfoutput> </cfif>

Function to Convert the first letter of a string to Capital in coldfusion

<cfform>       Enter the String: <cfinput type="text" name="strUcase">       <cfinput type="submit" name="btn_ucase" value="Submit"> </cfform> <cfif isdefined ('form.btn_ucase')>       <cfinvoke method="CapFirst" returnvariable="str1">       <cfinvokeargument name="str" value="#form.strUcase#">       </cfinvoke>       <cfoutput>Converted String is: #str1#</cfoutput> </cfif>     <cffunction name="CapFirst" returntype="string" output="false">     <cfargument name="str" type="string" required="true" />         <cfset var newstr = "" />       <cfif Len (str) GTE 1 >             <cfset newstr = UCase ( left (arguments.str,1)) & Right (arguments.str, Len (arguments.str)-1)>       </c

Query to XML and XML to query in coldfusion

<!--- Query To XML, apart from xml packet creation, this will create a new  myDoc.xml file :start---> <cfquery name="empdetails" datasource="empdetails">     select empid,empname,empage,country,state,empsalary from empdetails </cfquery> <cfxml variable="xmlPacket">       <employees>         <cfoutput query="empdetails">             <employee id="#empid#">                                   <address>                     <empname>#empname#</empname>                     <empcountry>#country#</empcountry>                     <empstate>#state#</empstate>                 </address>                 <other>                     <empage>#empage#</empage>                     <empsalary>#empsalary#</empsalary>                 </other>             </employee>         </cfoutput>     </employ

Collapsible Div

<script language="javascript"> function togglefun() {     var ele = document.getElementById("toggleText");     var text = document.getElementById("displayText");     if(ele.style.display == "block") {             ele.style.display = "none";         text.innerHTML = "[+]";       }     else {         ele.style.display = "block";         text.innerHTML = "[-]";     } } </script> <a id="displayText" href="javascript:togglefun();">[+]</a> Click here <div id="toggleText" style="display: none"><h1>Iam Collapsible Div</h1></div>

Email Validation in coldfusion

 <cfif isDefined("form.MailTo")>     <cfset valid = REFind("^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$", Trim(form.MailTo), 1) gt 0>     <cfif (form.MailTo NEQ 'Enter an email address') AND (form.MailTo NEQ '') AND (valid EQ 'YES')  >          <cfmail to = "#form.MailTo#" from = "xyz@mail.com" subject = "test"  type="text/html" >                   test             </cfmail>           <div ><h2>Email sent successfully!</h2><p>to:  <cfoutput>#form.MailTo#</cfoutput></p></div>     <cfelse>         <div ><h2>Email not sent. No valid email address supplied.</h2></div>     </cfif> </cfif> <form action = " " method="post" >         <h2>Email to:</h2> <input type = "Text" name =

Coldfusion code to remove illegal characters

<cfset s="FFFFt frgrth @!$?BNBNMJK %^&*()  LÖÖҗҢџьлÖҗҢџьлÖҗҢџьлÖҗҢџьлJLUIOUIO">  <cfset a=REReplace(s, '[^\x00-\x7F]', ' ', "ALL")>  <cfoutput>#a#</cfoutput>

how to limit the number of characters in textarea

<script language="javascript" type="text/javascript"> function limitText(limitField, limitCount, limitNum) {     if (limitField.value.length > limitNum) {         limitField.value = limitField.value.substring(0, limitNum);         alert("your message exceeds the limit");     } else {         limitCount.value = limitNum - limitField.value.length;     } } </script> <form name="myform" action=""> <textarea id="t1" name="description" onpropertychange="limitText(this.form.description,this.form.countdown,10);"  OnInput="limitText(this.form.description,this.form.countdown,10);" onKeyDown="limitText(this.form.description,this.form.countdown,10);" rows="20" cols="40"> </textarea><br> <font size="1">(Maximum characters: 10)<br> You have <input readonly type="text" name="countdown&quo

code similar to cflocation which gives a pop up message

<html> <head> <script type="text/javascript"> var t = 1000; function display() { var msg = confirm("activity is successful without attachment"); if (msg) location.href="http://shemy-coldfusion.blogspot.in"; else location.href="http://www.google.com"; } </script> </head> <body onLoad="javascript:setTimeout('display()', t);"> </body> </html>

Progress Bar in coldfusion

<html>     <head>         <script>             function init()                 {                      ColdFusion.ProgressBar.start("pb")                }         </script>     </head>     <body>         <h2>Processing....</h2>         <cfprogressbar name="pb" duration="5000" interval="20" width="300" />         <cfset ajaxOnLoad("init")>     </body> </html>

Code to find the number of functions in the current coldfusion version

<cfset fList = GetFunctionList () > <cfoutput> # StructCount ( fList ) # functions </cfoutput>< br > <cfloop collection = "#fList#" item = "key" >       <cfoutput> #key# < br ></cfoutput> </cfloop>