Form Field Woes

I was working on something today… more of a proof of concept. I had a dynamic form from which the user would fill it out and click submit. They would then see if they filled it out correctly.

Well, I got a little stumped for a second or two regarding it… how would I check if the question was processed. Usually I do:

IsDefined("form.fieldname")

But with my question looking like:

answer_#q.question_id#

I couldn’t quite do that. CF kept telling me it hated me. (Honest, those were its exact words.)

So I had to figure something out. At first I thought I’d have to use Evaluate… but well would you know that would be the wrong course of action? Ran across a website that told me to do this:

form["answer_#q.question_id#"]

Would you know that it worked? Oh yes it sure did work. So that made my day.

Using like in a cfqueryparam

So there I was… attempting to figure out the best way to to a like clause in a query statement using the cfqueryparam tag.

I had it coded like this:

like <cfparam cfsqltype="cf_sql_varchar" value="#arguments.search_criteria#">

Well that didn’t work. So I did some googling. After a little bit of searching, I finally found out how it should be coded.

like <cfparam cfsqltype="cf_sql_varchar" value="%#arguments.search_criteria#%">

After laughing at how simple that was… I used it. Worked like a charm.

MySQL DateTime

Been attempting to put a datetime variable into a MySQL Database via ColdFusion. For the life of me, I couldn’t figure out what I was doing wrong.

At first I tried:

#createODBCDateTime(now())#

For some reason that was only giving me the date and not the time.

Then I tried splitting up the date and time into two different fields, one for the date and the other for the time. Then I tried this code:

#createODBCDate(now())#

#createODBCTime(now())#

That gave me the date, but still not the time. Well I did some searching and then found there’s a built in function in MySQL to do this. Why not.

Talk about simple:

NOW()

Well guess what, it worked just like a charm.

Hello World In ColdFusion

Ah now we come to ColdFusion. Such a great language to be programming websites in. I figured since I created a Hello World sample app in other languages, why not here. Here’s the most basic output for ColdFusion:

<cfoutput>Hello World</cfoutput>

Of course we can make it a bit more fun… by using a variable to hold the “Hello World” in and then output that variable. In the next example, we’ll use greetings as the variable.

<cfset greetings="Hello World">
<cfoutput>#greetings#</cfoutput>

So yep that’s that, simple enough.

ColdFusion Good Times

ColdFusion has come a long way since I first started using it back in 2003. I started using version 5.0. It was at that time owned by Macromedia.

Later on Macromedia was bought out by Adobe. I’m sure some were afraid that Adobe would cease production of ColdFusion, but they were good and played nice, keeping CF around.

ColdFusion is currently in version 9. Not sure when version 10 will be released, but I’m sure it will have some good stuff to go with it. The updates usually do.

Some things I find interesting about ColdFusion are the following:

  1. Rabid application development
  2. Integrate Java in with your pages, via cfc’s or scripting
  3. Works nicely and plays well with others
I’ll come up with a better list later, but right now those come to mind. I mean it better play nice with Java, it was re written using Java altogether.