Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CFML FW1 Declaring Variables

Posted on 2014-01-22
2
Medium Priority
?
250 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 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

PROBLEM: How to add your own buttons to the bottom toolbar with paging info ( result count ). While creating a cfgrid, I ran into an issue where I wanted to embed my own custom buttons where the default ones ( insert / delete / etc… ) are for aes…
CFGRID Custom Functionality Series -  Part 1 Hi Guys, I was once asked how it is possible to to add a hyperlink in the cfgrid and open the window to show the data. Now this is quite simple, I have to use the EXT JS library for this and I achiev…
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…
Loops Section Overview
Suggested Courses

916 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