Solved

CFML FW1 Declaring Variables

Posted on 2014-01-22
2
235 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

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…
There is a huge demand for CodeIgniter among the PHP web developers due to its dynamic features and benefits these days. It is one of most popular and agile open source PHP framework for creating robust web applications in PHP web development field.…
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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

708 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

13 Experts available now in Live!

Get 1:1 Help Now