Integrate Coldfusion in Joomla (PHP)

So I have a couple sites I manage with Joomla and recently needed to code a customized online membership form that would interact with PayPal.  Because I know CFML much better than PHP, I wanted to code this portion with Coldfusion.  The only trick was how does one get CFML to execute withing a PHP template?  Turns out it is easy with the Joomla “wrapper” feature. 

The way it works is to first create your CFML templates.  I did them without any extra formatting knowing they would be included withing an iframe generated by Joomla.  Then, I just created a new menu item within Joomla that was of type “Wrapper”.  One of the elements of such a menu item is called the, “Wrapper Link”.  You just provide a fully qualified URL to your CFML template (could even reside on another server) and Joomla will process the request and pull in all it’s contents.  It worked perfectly for me with the exception that I had to watch my margins carefully because you are limited in width to the size of the iframe available in Joomla.  This will depend on the layout you use with Joomla of course.  But there you go, no reason you must be limited to PHP, Perl, Coldfusion or any other scripting language for that matter.  The working application can be seen here.

Don’t name cfinput form variables with “_time”

So this makes no sense to me at all, and it might be so terribly rare that you will never see it happen. If you use CFFORM and CFINPUT and you have two form fields of almost the same name (tack “_time” on to one of the form fields’ name) the internal coldfusion server side validation will null out the value of the form field without “_time” in its name. Whew, that was a mouthful, let me try to explain with an example. Take the following example code:

Date: <cfinput type=”text” name=”start_outage” validate=”date” required=”yes” value=”4/30/2008″><br />
Time: <cfinput type=”text” name=”start_outage_time” validate=”time” required=”yes” value=”11:54 PM”><br />

If you submit a form with these two fields, you will end up with the following output for your date field :

1899-12-30

Where the heck did that come from? Well, as it turns out, if you try to perform date functions, like DateFormat() on a zero value, it will produce the date 1899-12-30 which is I think Coldfusion’s answer to the UNIX Epoch. Anyway, I’ve got bad data, but I’m keying good data. Finally, I find a post in another discussion that indicates there is some built in server side validation Coldfusion will perform if it comes across a form field that ends with “_time”. It just so happens that a side effect is zeroing out the value of a date field that has the same form field name without the “_time” at the end. In this case the names were:

start_outage for the DATE
start_outage_time for the TIME

As soon as I changed the name of my date field to “start_outages” everthing worked. Also, changing the time field name to “start_outagetime” fixed performance and I had no more zeroed out dates. Even stranger that made debugging this problem hard was that the debug output at the bottom of my web page plainly displayed the values I expected for all of my form fields, however, as soon as I tried to output the form variables, all the dates that had matching time form fields were all zeroed out and showing “1899-12-30″.

Whew! It’s all over now and hopefully this information will help someone else out there. Here is a complete listing of code that will reproduce the problem, just paste into a single CFML template and run it:


<cfform action=”#script_name#” method=”post”>
Date: <cfinput type=”text” name=”start_outage” validate=”date” required=”yes” value=”4/30/2008″><br />
Time: <cfinput type=”text” name=”start_outage_time” validate=”time” required=”yes” value=”11:54 PM”><br />
<input type=”hidden” name=”formAction” value=”submit” />
<input type=”submit” value=”submit” />
</cfform>

<cfif formAction eq “submit”>
<cfoutput>
MySQL Date/Timestamp = #DateFormat(form.start_outage,”yyyy-mm-dd”)# #TimeFormat(form.start_outage_time,”hh:mm tt”)#
</cfoutput>
</cfif>

Playing with Flex Builder 3

So I recently downloaded Flex Builder 3 in an effort to broaden my horizons a bit. This is really my first exposure to Flex and I must say I’m pleasantly surprised with what it can do. However, there to is a dark side to this product. I found the number of well documented examples to learn from on the weak side. Being that the core of what I do with applications is create interfaces to databases, I wanted to do the same thing with Flex. I found an abysmal number of examples on the web and those I did find all seemed to have some kind of problem or another that wouldn’t work in my environment. In the end, I got the Adobe Coldfusion/Flex Data tutorial to work but there were mixed results.

It worked great from the get go on my localhost (Windows Vista with CF8/Apache/MySQL) but trying to deploy to a test Linux server failed badly in one instance and worked great on another (the difference being the version of Linux in use). It also worked well deployed on my shared host which runs on a Windows server with CF8/IIS. There were lots of steps I had to do over and over in the project setup of Flex Builder and of course you need to ensure your Coldfusion server is set to support Flash Remoting at the least. I will likely produce a step by step tutorial as time permits but for now the working example will have to do:

http://brad.melendy.com/projects/flex/DataTest4/DataTest4.html

You can right click the application and choose VIEW SOURCE to see exactly what it takes, the primary components are DataTest4.mxml, EmployeesCRUD.as and employees.cfc. Since Flex apps must get all their data from XML, the CFC acts as a middle man between the application and the database. I hope to begin a real application at work using Flex in the next couple months and I’ll try to document any technical pitfalls or discoveries here.

Put a pause in your code

So the other day I needed to put a pause in my code.  This is something I seem to run into every so often, but this time I decided to put the solution into a custom tag, making it much easier to include in my code.  I had previously looked around quite a lot and there are many ways to skin this particular cat, but in this case I turned to Java now that we have CFMX.  In particular the threed.sleep() method.  It is a method of the Thread class that can create a pause measured in milliseconds.  The raw Java code looks like this:

 try {
Thread.sleep ( 1000 );
}
catch ( InterruptedException e ) {
}

Now I need to get a quick implementation in the form of a custom tag that I could easily include in my code, providing a way to pass an argument in seconds rather than milliseconds.  The resulting code was my new custom tag:

<cfparam name=”seconds” default=”1″>
<cfset seconds = attributes.seconds>
<cfif not(isnumeric(seconds))>
<cfset seconds = 1>
</cfif>

<cfscript>
thread = createObject(”java”, “java.lang.Thread”);
thread.sleep(javaCast(”long”, 1000*#seconds#));
</cfscript>

Notice I do check to see if the value passed is actually numeric and if not, I just force the tag to default to one second.  Now I just call my tag like so:

<cf_pause seconds = 1>

There you have it, a nice pause for your code provided you can keep the tag (pause.cfm in this case) in your CustomTags folder OR in the current working directory.

Hello World…

After many hours, days and possibly weeks of evaluation, I’ve decided to start my professional and coding blog with Wordpress.  I’m primarily a Coldfusion developer so I really wanted to eat my own food so to speak, but in the end, I couldn’t turn away from the ease of use and vast support of Wordpress.  I tried BlogCFC, CFBloggy and a couple other CFML based blogs and CMS systems (FarCRY) but I continued to run into obstacles. 

Some of my problems were to do with my host, Godaddy.  Though cheap, you give up some depth with the very restrictive nature of their Coldfusion setup.  CFObject is blocked and pretty much all the blogs and cms systems are using that.  I read some articles about manually switching things over to CFInvoke, however that proved time consuming and what was one to do when a new release of the software came out?  No, I needed to work with something that would require little effort to update from one version to the next. 

By the time I decided to go with Wordpress, I had setup a second hosting account with Hostek which supported CFObject and CF8 to name a few key pionts, but just the same, I ended up with Wordpress because it just plain worked everywhere I used it.  So now that I can actually run all these other great CFML based apps just fine, I still choose to use Wordpress after all was said and done.  Hopefully the Coldfusion Gods won’t hold it against me.  ;-)

That all being said, I look forward to documenting some of my work related pitfalls surrounding CFML and system administration.  I’m dying to share my experiences regarding whether or not shared hosting is better than running your own server so maybe that will be next.Â