Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CFML FW1 Declaring Variables

Posted on 2014-01-22
2
Medium Priority
?
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Stack Overflow Podcast - Developer Story

Welcome to the Stack Overflow podcast recorded Thursday July 20 at Stack Overflow Headquearters in NYC. Your hosts today are podcast regulars Jay Hanlon, David Fullerton, and Ilana Yitzhaki, plus the quite irregular Matt Sherman (Stack Overflow Engineering Manager extraordinaire)

Question has a verified solution.

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

Today, I was working on some optimization and spam-stopping techniques when I encountered Ben Nadel's post to reduce spam feature using Math (http://www.bennadel.com/blog/197-How-I-Stop-Spammers-On-My-ColdFusion-Blog.htm). While this method is not o…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

704 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