Solved

CFML FW1 Declaring Variables

Posted on 2014-01-22
2
238 Views
Last Modified: 2014-01-23
So far what I have is... I think pretty simple. I'm trying to move a legacy system into a FW1 application.

When I run this, I'm getting "Variable POPULATEBODY is undefined."

<cfscript>
	application.cfstatic.include("/js/modules/email/sendemail.js");
	rc.active = "email";
	rc.populatebody = "form.comment"; 
</cfscript>
<form action="" method="POST" name="sendMessage" class="sendMessage" id="sendMessage">
		<input type="hidden" name="sendemail" value="yes">
		<input type="hidden" id="nTierID" name="nTierID" value="<cfoutput>#session.CurrentTierID#</cfoutput>">
  
	<div class="row-fluid">
		<div class="center">
		<h3>Send Email</h3>
       	</div>
        <div class="center">
        	<table align="center">
            	<tr>
                	<td valign="middle" align="right"><strong>REPLY TO ADDRESS:</strong></td>
                    <td><input type="text" name="emailfrom" message="Be sure to include a Reply To address " value="<cfoutput><cfif isDefined('populateFrom') AND Len(Trim(populateFrom))>#populateFrom#<cfelseif isDefined('REQUEST.emailus') AND Len(Trim(REQUEST.emailus))>#REQUEST.emailus#<cfelse>#client.email#</cfif></cfoutput>" size="60"></td>
              	</tr>
                <tr>
                	<td valign="middle" align="right"><strong>SUBJECT:</strong></td>
                    <td><input type="Text" name="subject" value="<cfoutput><cfif isDefined('populateSubject') AND Len(Trim(populateSubject))>#populateSubject#<cfelse>A Message From The Admins</cfif></cfoutput>"size="60" maxlength="200"></td>
             	</tr>
          	</table>
            
         	<p style="text-align:center">
				<br />
				<strong>Your Message:</strong>
				<br />
                <cfmodule template="/assets/tags/editors/richtexteditor.cfm"
                    basePath="fckeditor/"
                    instanceName="comment"
                    height="300"
                    toolbarset="#request.classificationToolbar#"
                    value="#populateBody#"
                    width="95%"
                >
				<br />
				<br />
			       
 	</div>
                      
        
</form>

Open in new window



I guess I do not know how to declare/define variables. What I want to say is this:

if(structKeyExists(form, "comment")){
				populateBody = FORM.comment;
			}else{
				populateBody = '';
			}

Open in new window


But I do not know where to place it within the code... or the controller... or where you begin to declare variables in this manner. Any suggestions?
0
Comment
Question by:traport
2 Comments
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 39802983
If this page is expecting certain values to be passes, I think it is good form to show those variables at the top of the page using CFPARAM.  If the values are not required you can add "default" tag, if they are required, you can leave it off.  That way any future developers can easily see what values may be passed to this page.

<cfparam name="form.comment" default="">

<cfset populateBody = form.comment>

This method, IMHO, is much neater than having long <cfif statements inside of your value tag.    Also, in my opinion, you do not want to always have to check to see if a variable is defined throughout a template.    If the template requires it, cfparam it at the top and that's it for the rest of the code.

if the value is required, then remove the "default" tag..

<cfparam name="form.comment">

This will throw an error if form.comment is not passed in..
0
 

Author Closing Comment

by:traport
ID: 39803015
Thanks so much.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The technique is by far very Simple! How we can export the ColdFusion query results to DOC file?  Well before writing this I researched a lot in Internet but did not found a good Answer anyways!  So i thought now i should share my small snippet w…
Hi. There are several upload tutorials using jquery and coldfusion. I found a very interesting one here Upload Your Files using Jquery & ColdFusion and Preview them (http://www.randhawaworld.com/) . I did keep the main js functions but made sever…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now