Download the EasyCFM.COM Browser Toolbar!
Pass complex data in a hidden form field with Base64
Pass complex data in a hidden form field with Base64

Sometimes it is desirable to pass large blocks of text or HTML from page to page without using session variables. You can use this technique to pass html or large blocks of text in a form post.

Another advantage of this technique is that the value isn't readable by viewing the page's source.

Steps
  1. The first step is to generate what you want to pass using cfsavecontent.
  2. Pass the string by using toBase64() and setting the value of a hidden form field.
  3. On the action page, decode the string like so: toString(toBinary(Variable_Here))

<cfoutput>
    <cfsavecontent variable="request.HiddenValue">

        <div style="border: 1px solid ##ccc; padding:10px; margin-left: 20px; width: 300px;">
        <p>
Thanks for your order, here are your order details:</p>
        <!--- This could be static or content generated from a query --->
        
<table>

            <tr>
                <th>
Customer</th>
                <td>
[Customer Name]</td>
            </tr>
            <tr>
                <th>
Date/Time</th>
                <td>
#Now()#</td>
            </tr>
            <tr>
                <th>
Order Detail</th>
                <td>
[Order Detail]</td>
            </tr>
        </table>

        <a href="http://#cgi.SERVER_NAME#/review_order.cfm?orderid=[Order ID from Database]">Some misc link</a>
        </div>
    </cfsavecontent>
    <table>
        <tr>
            <td id=
"leftcolumn" style="border: 1px solid ##000; padding:10px; width: 350px;">
                <h3>Form where data is passed</h3>
                <form name="myform" method="post" action="#cgi.SCRIPT_NAME#">
                    <p>Some Value <input type="text" name="SomeValue" value=""/></p>
                    <p>The following will be passed in the form:</p>
                    <!--- You could optionally display the value you are going to pass to the action page --->
                    <p>#request.HiddenValue#</p>
                    <!--- to pass the complex value, convert it to Base64 --->
                    <input type="hidden" name="hiddenvalue" value="#toBase64(request.HiddenValue)#"/>
                    <input type=
"submit" name="go" value="Submit">
                </form>

            </td>
            <td id=
"rightcolumn" style="border: 1px solid ##000; padding:10px; width: 350px;">
                <cfif structkeyexists(FORM,"fieldnames")>
                    <h3>Results where data is passed</h3>
                    <table>
                        <tr>
                            <th>
Some Value</th>
                            <td>
#FORM.SomeValue#</td>
                        </tr>
                        
<!--- display the value as it was passed --->
                        <tr>
                            <th>
Base64 Value</th>
                            <td>
<textarea rows="3">#FORM.HiddenValue#</textarea></td>
                        </tr>
                       
 <!--- display the original value by first converting it to binary, then back to a string --->
                        <tr>
                            <th nowrap=
"nowrap">Base64 Value<br/> (after conversion)</th>
                            <td>
#toString(toBinary(FORM.HiddenValue))#</td>
                        </tr>
                    </table>

                </cfif>
                </td>
            </tr>
        </table>

</cfoutput>



All ColdFusion Tutorials By Author: Nathan Miller