Simon Bingham’s Stuff

Web Developer 

Replacing String Placeholders With Query Values In ColdFusion

This function can be used to replace placeholders in a string with data from a query row.

<cffunction name="replacePlaceholders" access="public" returntype="string" output="FALSE">
    <cfargument name="str" type="string" required="TRUE" />
    <cfargument name="qry" type="query" required="TRUE" />

    <cfset var index="" />
    <cfset var columnName="" />
    <cfset var placeholders="" />

        <cfset placeholders = REMatchNoCase( '\$\{[a-z_]{1,}\}', arguments.str ) />

        <cfloop array="#placeholders#" index="index">
        <cfset columnName = REReplaceNoCase( index, '[^a-z_]', '', 'ALL' ) />

                <cfset arguments.str=ReplaceNoCase( arguments.str, index, arguments.qry[ columnName ][ 1 ], 'ALL' ) />
    </cfloop>       

        <cfreturn arguments.str />
</cffunction>

For example, a string containing "${foobar}" such as "Lorem ${foobar} ipsum" will be replaced with "Lorem abcd ipsum" where "abcd" is the value of the "foobar" query column.

Thank you to John Whish for helping me write this function.

Loading mentions Retweet
Filed under  //   coldfusion  

Comments [0]

Sending Email Using CFSCRIPT In ColdFusion 9

Here's how it's done...

---

// Create an instance of the mail object
mail=new mail();

// Set it's properties
mail.setSubject( "Sample Email" );
mail.setTo( "to@example.com" );
mail.setFrom( "from@example.com" );
mail.setCC( "cc@example.com" );
mail.setBCC( "bcc@example.com" );

// Add an attachment
mail.addParam( file="C:\foo.txt" );

// Add email body content in text and HTML formats
mail.addPart( type="text", charset="utf-8", wraptext="72", body="This is a test message." );
mail.addPart( type="html", charset="utf-8", body="<p>This is a test message.</p>" );

// Send the email
mail.send();

---

More information about using the CFMAIL tag in CFSCRIPT can be found at http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSe9cbe5cf462523a0693d5dae123bcd28f6d-7ff9.html.

Loading mentions Retweet
Filed under  //   coldfusion  

Comments [1]

My First Attempt At ORM In ColdFusion 9

Ok, this is my first attempt at using ColdFusion 9's built-in ORM features (and I'm very impressed!).

Download Sample Files

You can view the code, but will need to have ColdFusion 9 installed and the cfartgallery datasource which comes with the installation setup to execute it.

Loading mentions Retweet
Filed under  //   coldfusion  

Comments [0]

How To Fix An Annoying SWFObject Bug In IE6

I recently used SWFObject to embed a Flash movie on a website home page. The Flash movie worked fine in all browsers except IE6 where I got the following error.

Internet Explorer cannot open the Internet site XXXX. Operation aborted.

To overcome this problem add defer="defer" to the script tag as shown below.

---

<script language="JavaScript" type="text/javascript" defer="defer">
var flashvars={};
var params={wmode:"transparent"};
var attributes={};

swfobject.embedSWF("filepath", "homePageVideo", "456", "300", "9.0.0", "filepath", flashvars, params, attributes);
</script>

---

More information about fixing this bug can be found here.

Loading mentions Retweet
Filed under  //   javascript  

Comments [0]

How To Fix The Fieldset Background Color Overflow Bug In Internet Explorer (IE)

To fix the IE fieldset background color overflow bug in Internet Explorer (IE) do the following.

---

fieldset {
    position: relative;
    margin: 0 0 1em 0;
    background: #ffffcc;
}

legend {
    position: absolute;
    top: -.5em;
    left: .2em;
}

Loading mentions Retweet
Filed under  //   css   ie  

Comments [0]

Problem With Superfish Menu Being Hidden Behind Flash Content

If you use the Superfish Menu jQuery Plugin for your website you may find that the dropdown menus disappear behind any Flash content you might have on your website. You can easily overcome this problem by adding wmode="transparent" to the object tag for your Flash content.

Loading mentions Retweet
Filed under  //   jquery  

Comments [0]

HTML5 Boilerplate Template

Here is a complete and compatible HTML5 boilerplate template.


<!DOCTYPE html>

<html>
    <head>
        <meta charset=utf-8 />

        <title>HTML 5 complete</title>

        <!--[if IE]>
        <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

        <style>
            article, aside, dialog, figure, footer, header,
            hgroup, menu, nav, section { display: block; }
        </style>
    </head>

    <body>
        <p>Hello World</p>
    </body>
</html>


Source: html5doctor.com

Loading mentions Retweet
Filed under  //   html   html5   webdesign  

Comments [0]

My First HTML 5 Document

This is my first attempt at creating an HTML 5 document. And it validates!

To view the code in a web browser that won't self destruct when rendering an HTML 5 document you can use the latest version of Opera.


<!DOCTYPE html>

<html>
    <head>
        <title>My First HTML 5 Document</title>

                <meta charset="utf-8" />

                <style>
        body{
            width:980px;
            margin:0 auto;
        }

                header, nav, section, article, aside, footer{
            margin-bottom:10px;
        }

        nav ul{
            margin:0;
            padding:0;
        }

                nav li{
            display:inline;
            margin-right:20px;
        }

                section{
            float:left;
            width:60%;
        }

        article{
            float:left;
            width:60%;
        }

                article article{
            width:100%;
            border:1px solid #CCC;
            padding:10px;
        }

        aside{
            float:right;
            width:40%;
        }

                footer{
            clear:both;
            display:block;
        }
        </style>
    </head>

    <body>   
        <header>
            <h1>My First HTML 5 Document</h1>

                        <p>By Simon Bingham</p>
        </header>

                <nav>
            <ul>
                <li>Link</li>
                <li>Link</li>
                <li>Link</li>
                <li>Link</li>
                <li>Link</li>
            </ul>
        </nav>

                <aside>
            <header>
                <h1>Latest News</h1>
            </header>

                    <ul>
                <li>Link</li>
                <li>Link</li>
                <li>Link</li>
                <li>Link</li>
                <li>Link</li>
            </ul>           

                    <header>
                <h1>Upcoming Events</h1>
            </header>

                    <ul>
                <li>Link</li>
                <li>Link</li>
                <li>Link</li>
                <li>Link</li>
                <li>Link</li>
            </ul>           
        </aside>       

                <section>
            <header>
                <h1>Section</h1>
            </header>

                    <p>Donec fermentum sodales aliquet. Phasellus volutpat sapien sit amet ipsum vestibulum ac venenatis diam bibendum. Duis in neque odio, sit amet bibendum arcu. Mauris tortor erat; dictum non gravida ac; adipiscing non dolor. Duis ultrices diam auctor nisi consectetur tincidunt? Pellentesque eleifend aliquam tempus. Donec in mauris ac tortor pretium ultricies eu nec augue. Suspendisse potenti. Proin fermentum tincidunt est, ac faucibus mauris blandit imperdiet. Aliquam turpis sapien, viverra a condimentum sagittis, imperdiet a magna? Ut congue scelerisque augue eu gravida.</p>
        </section>

                <article>
            <header>
                <h1>Article</h1>
            </header>

            <p>Donec fermentum sodales aliquet. Phasellus volutpat sapien sit amet ipsum vestibulum ac venenatis diam bibendum. Duis in neque odio, sit amet bibendum arcu. Mauris tortor erat; dictum non gravida ac; adipiscing non dolor. Duis ultrices diam auctor nisi consectetur tincidunt? Pellentesque eleifend aliquam tempus. Donec in mauris ac tortor pretium ultricies eu nec augue. Suspendisse potenti. Proin fermentum tincidunt est, ac faucibus mauris blandit imperdiet. Aliquam turpis sapien, viverra a condimentum sagittis, imperdiet a magna? Ut congue scelerisque augue eu gravida.</p>

                    <article>
                <header>
                    <h2>Comment 1</h2>
                </header>

                            <p>Donec fermentum sodales aliquet. Phasellus volutpat sapien sit amet ipsum vestibulum ac venenatis diam bibendum. Duis in neque odio, sit amet bibendum arcu. Mauris tortor erat; dictum non gravida ac; adipiscing non dolor. Duis ultrices diam auctor nisi consectetur tincidunt? Pellentesque eleifend aliquam tempus. Donec in mauris ac tortor pretium ultricies eu nec augue. Suspendisse potenti. Proin fermentum tincidunt est, ac faucibus mauris blandit imperdiet. Aliquam turpis sapien, viverra a condimentum sagittis, imperdiet a magna? Ut congue scelerisque augue eu gravida.</p>
            </article>

                    <article>
                <header>
                    <h2>Comment 2</h2>
                </header>

                <p>Donec fermentum sodales aliquet. Phasellus volutpat sapien sit amet ipsum vestibulum ac venenatis diam bibendum. Duis in neque odio, sit amet bibendum arcu. Mauris tortor erat; dictum non gravida ac; adipiscing non dolor. Duis ultrices diam auctor nisi consectetur tincidunt? Pellentesque eleifend aliquam tempus. Donec in mauris ac tortor pretium ultricies eu nec augue. Suspendisse potenti. Proin fermentum tincidunt est, ac faucibus mauris blandit imperdiet. Aliquam turpis sapien, viverra a condimentum sagittis, imperdiet a magna? Ut congue scelerisque augue eu gravida.</p>
            </article>

            <footer>Footer information for article.</footer>
        </article>

                <footer>&copy; Your Company Name.</footer>
    </body>
</html>


More information about HTML 5 can be found at html5doctor.com.

Loading mentions Retweet
Filed under  //   html5   webdesign  

Comments [0]

The SQL Case Statement

SQL Server and MySQL provide a mechanism for returning different values in a SELECT clause based on Boolean conditions: the CASE statement.

Here is some sample code:


SELECT
    product_id
    , product_title
    , CASE WHEN LEN( product_imagethumb ) > 1 THEN
        product_imagethumb
    ELSE
        'no-image.gif'
    END AS product_imagethumb
FROM products
ORDER BY product_title


More information about the CASE statement can be found here:

Loading mentions Retweet
Filed under  //   mssql   mysql   sql  

Comments [0]

Notes From Future of Web Design (FOWD) Bristol 2009

I'm not sure this will be of use or whether anyone will even be interested, but here are my entirely uncomprehensive notes from the conference.

Unfortunately my thoughts were turning to beer and food when Bruce Lawson did his final presentation so I didn't make any notes (sorry Bruce!).

 

 

Loading mentions Retweet
Filed under  //   fowd   webdesign  

Comments [0]



--- More information about fixing this bug can be found here."}; var fb_comment_action_link_6574719 = [{"text":"Read more on Posterous","href":"http://simonbingham.posterous.com/how-to-fix-an-annoying-swfobject-bug-in-ie6"}];