Archive for the ‘ColdFusion’ Category

ColdFusion Implementation of Virtual Merchant

Tuesday, April 8th, 2008

CF Webtools works on plenty of e-commerce sites. Some generate only a trivial amount of revenue and others generate millions every year. The most common implementations we see and deal with are authorize.net and paypal. Both have very standard APIs and a feature list that is continuously expanding. Recently I was given a project which required implementing Virtual Merchant into Site Director and Farcry. It also required the ability to use multiple merchants through the same implementation in Farcry. Here’s what I did…

(more…)

BlogCFC Last ‘n’ Entries

Wednesday, September 19th, 2007

A question came my way today about Ray Camden’s BlogCFC and I hope I’m not stepping on Ray’s toes by answering it. Someone wanted to know how to configure the default entries that show up. Some of his were dropping off after a certain time frame and he wanted to increase the default time frame. So, here’s how it’s done…

Blog.cfc in org/Camden/blog in the blog’s install folder has a function getEntries() which takes a ‘params’ structure. The ‘params’ structure is passed to the function in index.cfm of your blog instance. Here’s that code:

<cftry>
      <cfset articles = application.blog.getEntries(params)>
      <!--- if using alias, switch mode to entry --->
      <cfif url.mode is "alias">
            <cfset url.mode = "entry">
            <cfset url.entry = articles.id>
      </cfif>
      <cfcatch>
            <cfset articles = queryNew("id")>
      </cfcatch>
</cftry>

(more…)

CFMAILPARAM Sender

Friday, September 7th, 2007

I’m writing this to hopefully allow other people to avoid the issues I’ve had with one of the sites I support. This particular client’s business revolves around sending emails so it is obviously important that the end user receive those emails. Spam filters are more and more getting in the way. One thing you have to really think about when sending the email is “What will this email look like to the receiving server?” If you are on domain.com and you send an email using cfmail and the from address is a domain.com address, there is no problem. It’d be like sending that same message through Outlook using a domain.com address and domain.com relay (SMTP) server.

What if you have a form allowing a random user to send an email?This is where SPF filtering can block your message. They put in their from email address and to email address and whatever other data and that information gets stuck into the cfmail tag. Now, you might have an email address FROM someone@from.com TO someone@to.com. The email was sent THROUGH the domain.com server. Now if to.com’s server acknowledges SPF filtering, it will look at the dns record for from.com and look specifically at the TXT record. A smart DNS entry will list IP addresses that are able to send email. If the IP address of domain.com’s mail server does not appear in the DNS record of to.com, then the message will be blocked.

Here’s an example of the TXT record from domain.com:

domain.com       86400   IN         TXT       "v=spf1 ip4:xx.xx.xx.xx ip4:yy.yy.yy.yy ip4:zz.zz.zz.zz -all"

The first 3 ip addresses would be valid mail servers. The –all says to reject anything that is not one of those 3 ip addresses.

The way around this is to use a cfmailparam tag with a valid email address for domain.com (make an email address if necessary like info@domain.com). Here’s what the resulting code looks like:

<cfmail to="#to#"  from="#from#" subject="#subject#" type="html">
<cfmailparam name="sender" value="valid_email@domain.com">
.
.
.
</cfmail>

I hope this helps some people out

Generic HTML Form error handler

Tuesday, March 27th, 2007

The guy I share an office with is a flex developer and often has problems with simple ColdFusion tasks like form error handling because he doesn’t do them enough. Perhaps others deal with the same situation.

Here’s a generic form error handler.

First, add a little snippet to the form display. I always change the form field label to red if the user did not enter data.

<span style="font-weight:bold;color:<cfif ListFindNoCase(form.errorfields, 'email')>red<cfelse>black</cfif>;">Email Address:</span>
<input type="text" name="email" value="<cfoutput>#form.email#</cfoutput>">

You notice the form.errorfields right? That gets generated in the event/error handler code.

// check for errors in form fields
for (i = 1; i LTE ListLen(form.fieldnames); i = i + 1) {
	if (NOT len(trim(form[ListGetAT(form.fieldnames, i)]))) {
		form.errorFields = listAppend(form.errorFields, ListGetAt(form.fieldNames, i));
	}
}

This simply checks to make sure all fields have data. It does not check the validity of that data so you will need to add that yourself. For an email field, add something like:

if (IsValid(”email”, form[ListGetAt(form.fieldnames, i)])

(This is CF7 specific)

One thing to note is that Radio buttons will not show up in the form.fieldnames if there is not a default value. To add them manually do:

form.fieldnames = ListAppend(form.fieldnames, “radioButton”);

If a field is not required, remove it from the list by doing this:

form.fieldnames = listDeleteAt(form.fieldnames, ListFindNoCase(form.fieldnames, “submitButton”));

Once again, this is very generic and can be extended to be much more robust. But, for a simple form, this works great.

Quick Browser Detection for CSS Script

Monday, November 13th, 2006

Here’s a quick script that I use in a lot of header files to detect the user’s browser. else represents Firefox in most cases.

<cfif Trim(ListGetAt(CGI.HTTP_USER_AGENT, 2, ";")) EQ "MSIE 6.0">
        <link rel="stylesheet" type="text/css" href="css/main_IE6.css" media="screen" />
    <cfelseif Trim(ListGetAT(CGI.HTTP_USER_AGENT, 2, ";")) EQ "MSIE 7.0">
        <link rel="stylesheet" type="text/css" href="css/main_IE7.css" media="screen" />
    <cfelse>
        <link rel="stylesheet" type="text/css" href="css/main_FF.css" media="screen" />
    </cfif>