I have a simple email form and CF script backing it. It should all be obvious, but the script is throwing up with valid input. I’ve verified that the expected values are in the header and I can output the values in the script, but it’s not liking the values for anything beyond output.
This is my HTML:
<form id="email" name="email" method="post" action="scripts/email.cfm">
<fieldset>
<legend>Email Student Government:</legend>
<!-- PASS NAME (to query email) to the script -->
<input type="hidden" name="who" id="who" value="Example User">
<label for="from">Your Email:</label><br>
<input type="email" id="from" name="from"><br>
<label for="message">Message:</label><br>
<textarea id="message" name="message" rows="4"></textarea>
<input type="submit" name="send" id="send" value="Send Email">
</fieldset>
</form>
The ColdFusion (including debugging script at top):
<!--- member email addresses, hashed by name --->
<cfinclude template="emailHash.cfm">
<cfoutput>
#FORM.SEND#
#FORM.WHO#
#FORM.FROM#
#FORM.MESSAGE#
</cfoutput>
<cfif isdefined("FORM.SEND") and FORM.SEND eq "Send Email">
<cfmail from="Example User <example@example.com>"
to="#FORM.WHO# <#emailHash['FORM.WHO']#>"
bcc="Example User <example@example.com>"
replyto="#FORM.FROM#"
subject="Email Form Submission">
Message: #FORM.MESSAGE#
Date / Time Sent: #dateformat(now(), "yyyy/mm/dd")# at #timeformat(now(), "HH:mm:ss tt")#
</cfmail>
</cfif>
If I run the script, the logical output is printed, but then this error follows even though the FORM.WHO value is clearly defined and printed just fine in the output directly prior:
Element FORM.WHO is undefined in a CFML structure referenced as part of an expression.
I’m pretty annoyed at what I thought was an easy project so any nudges in the right direction would be greatly appreciated!
PS: I thought the HTML5 input types might be causing issues so I tried trading them for a plain text type, but that didn’t do any good.
The problem isn’t with your form variables, it’s with this:
#emailHash['FORM.WHO']#Your error is saying that that variables doesn’t exist (the rest of the error message should point to the line number that that code is on? You didn’t post that bit…). And from what you’ve posted, there’s no evidence to suggest that it does.
What goes on in
emailHash.cfm?