Skip to main content
Known Participant
April 4, 2007
Question

JS not coming into play in CFFORM

  • April 4, 2007
  • 18 replies
  • 1387 views
I want the hidden textbox orange to take effect when non javascript browser or more importantly bots come by to fill out my form. Is there any reason the JS at the bottom isnt working? BTW im a beginneer.

<CFIF IsDefined("process")>
<!--- Send the message to yourself, when the user posts it on your site. --->
<CFMAIL to="taka-oshimi@mua.biglobe.ne.jp" from="#ContactEmail#" Subject="Contact From YourSite.Com">
#ContactMessage#
Message By: #ContactName# - #ContactEmail#
========================================
</CFMAIL>
<!--- Send one to the person writing, thanking them and reminding them what they wrote. --->
<CFMAIL to="#ContactEmail#" from="From Email" Subject="The Subject!">
You wrote:
#ContactMessage#
Message By: #ContactName# - #ContactEmail#
========================================
</CFMAIL>
<!--- If "Process" is not defined, let's show the form: --->
<CFELSE>
<cfform action="contact_us.cfm" method="post">
<input type="hidden" name="Process" Value="1">
<cfinput type="text" class="txtBoxes" name="ContactName" required="yes" message="Please Enter Your Name!">
<label class="txlb" accesskey="1"><span class="tx">Email (please enter an email address)</span></label>
<p>
<cfinput type="text" class="txtBoxes" name="ContactEmail" required="yes" message="Please Enter Your Email Address!">
</p>
<noscript>
<td>Enter 'orange' here:</td>
<td><input name='foil'/></td>
</noscript>
<div class="fieldset-footer">
<input type="submit" id=butComment onclick="jsAC();" value="Send">
</div>
</cfform>
</CFIF>

<script language="JavaScript" src="foil.js" type="text/JavaScript"></script>

Many thanks
This topic has been closed for replies.

18 replies

Known Participant
May 16, 2007
ok ok I know you all thought this was all over but .... it was working then I did something - have been trying over the last week to fix it but still not recieving mail
link - http://www.healthhokkaido.com/files/contact_us.cfm
using this code

<cfif isDefined("form.foil") and Trim(form.foil) IS NOT "orange">
<!--- bad submission. do nothing. --->
<cfelseif isDefined("form.process")>

<!--- Send the message to yourself, when the user posts it on your site. --->
<CFMAIL to="sapporomark@yahoo.com" from="#ContactEmail#" Subject="Contact From YourSite.Com">
#ContactMessage#

Message By: #ContactName# - #ContactEmail#
========================================
</CFMAIL>
<!--- Send one to the person writing, thanking them and reminding them what they wrote. --->
<CFMAIL to="#ContactEmail#" from="From Email" Subject="The Subject!">

Thank you for your message,
healthhokkaido will be in touch as soon as possible!



You wrote:
#ContactMessage#

Message By: #ContactName# - #ContactEmail#
========================================
</CFMAIL>

Thank you for contacting us. We will be in touch as soon as possible.

<!--- If "Process" is not defined, let's show the form: --->
<CFELSE>



<cfoutput><form action="#cgi.script_name#" method="post"></cfoutput>
<input type="hidden" name="Process" Value="1">
Name: <br><input type="text" class="txtBoxes" name="ContactName"><br>
<input type="hidden" name="ContactName_required" value="Please Enter Your Name!">

E-mail: <br><input type="text" class="txtBoxes" name="ContactEmail"><br>
<input type="hidden" name="ContactEmail_required" value="Please Enter Your Email Address!">



Message: <br> <textarea name="ContactMessage" class="txtBoxes" rows="10" cols="20"></textarea>
<input type="hidden" name="ContactMessage_required" value="Please Enter A Message.">

<script src="foil.js" type="text/JavaScript"></script>
<noscript><br>
<td>Enter 'orange' here:</td><br>
<td><input name='foil'/></td>
</noscript>
<br><br>
<input type="submit" id="butComment" value="Send">
</form></cfif>

any ideas
regards
Mark
Known Participant
April 6, 2007
OK BKBK looks like everything is function well

just check my inbox and only the mails where i wrote the word orange in came through.
I am really thankful for all you help over the last couple of days. And if i can ever help you out please let me know.

BIG UP BKBK
BKBK
Community Expert
Community Expert
April 6, 2007
how to scope the variables

Simply means to name a form variable form.myVar, a URL variable url.myvar, a local variable variables.myVar and so on. Thus, instead of process, foil, ContactEmail and ContactMessage within the if-block, you should use, respectively, form.process, form.foil, form.ContactEmail and form.ContactMessage. It might not change the result. However, it avoids confusion.

I'm glad that your code is functioning as you wished it to. Good luck with the site.

Known Participant
April 6, 2007
HI BKBK --> included the code

now with the js switch of and not putting the word orange in i do not get a thank you for your message. When i put the orange in i get thank you for your message. below is the code see what you think. To be honest im not sure how to scope the variables or what they are in simple terms.

<cfif isDefined("form.foil") and Trim(form.foil) IS NOT "orange">
<!--- bad submission. do nothing. --->
<cfelseif isDefined("form.process")>

<!--- Send the message to yourself, when the user posts it on your site. --->
<CFMAIL to="sapporomark@yahoo.com" from="#ContactEmail#" Subject="Contact From YourSite.Com">
#ContactMessage#

Message By: #ContactName# - #ContactEmail#
========================================
</CFMAIL>
<!--- Send one to the person writing, thanking them and reminding them what they wrote. --->
<CFMAIL to="#ContactEmail#" from="From Email" Subject="The Subject!">

Thank you for your message,
healthhokkaido will be in touch as soon as possible!



You wrote:
#ContactMessage#

Message By: #ContactName# - #ContactEmail#
========================================
</CFMAIL>

Thank you for contacting us. We will be in touch as soon as possible.

<!--- If "Process" is not defined, let's show the form: --->
<CFELSE>



<cfoutput><form action="#cgi.script_name#" method="post"></cfoutput>
<input type="hidden" name="Process" Value="1">
Name: <br><input type="text" class="txtBoxes" name="ContactName"><br>
<input type="hidden" name="ContactName_required" value="Please Enter Your Name!">

E-mail: <br><input type="text" class="txtBoxes" name="ContactEmail"><br>
<input type="hidden" name="ContactEmail_required" value="Please Enter Your Email Address!">



Message: <br> <textarea name="ContactMessage" class="txtBoxes" rows="10" cols="20"></textarea>
<input type="hidden" name="ContactMessage_required" value="Please Enter A Message.">

<script src="foil.js" type="text/JavaScript"></script>
<noscript><br>
<td>Enter 'orange' here:</td><br>
<td><input name='foil'/></td>
</noscript>
<br><br>
<input type="submit" id="butComment" value="Send">
</form></cfif>

Many thanks
Known Participant
April 6, 2007
Thanks BKBK Ill give this a try -- I am still learning coldfusion - I really enjoy it but just don't have the technical knowledge. I hope i can be of help to yu in the future.

Probably be writing again soon
BKBK
Community Expert
Community Expert
April 6, 2007
> Still can't quite get this too work though.
...
> when i have my javascript turned off and don't complete the
> 'orange' box the mail is still sent to me.


I think you've got the essence. Your HTML and Javascript are similar to that in the example. However, what you don't yet have is server validation code. In the example, they would have done it in PHP. So you cannot see it in the HTML source. You could do yours very simply in Coldfusion.

Scope the form variables, as Azadi advises you to do. Then modify the if-statement to

<cfif isDefined("form.foil") and Trim(form.foil) IS NOT "orange">
<!--- bad submission. do nothing. --->
<cfelseif isDefined("form.process")>

etc. etc.





Known Participant
April 6, 2007
Yep thats right --> apparently spam bots don't use javascript so its a easy way to avoid them. Still can't quite get this too work though.

Thanks for all your help BKBK
BKBK
Community Expert
Community Expert
April 5, 2007
I have looked at the example. I get it now. If Javascript is not enabled on the client, you want the client to enter the code word 'orange'. Why not make the message field a textarea, like

<textarea name="ContactMessage" class="txtBoxes" rows="10" cols="20"></textarea>

Known Participant
April 5, 2007
Yeah I know im just a bit out of my depth... Been getting a heap of span recently just wanted to stop it. Not sure what to do next but the original idea came from the dreamweaver forum for php --->

Email: http://makowiec.net/contact.php
is the example
Thanks for all your help might catch a few winks and come back at it tomorrow
Inspiring
April 5, 2007
1) scope your vars: all vars coming from form inputs should have a form.
prefix - this will save some CF processing time and help avoid errors if
you have several vars of different scopes named the same.

2) with javascript turned off you have to do server-side validation.
basic principle: check that required form fields are filled in using
<cfif>s; if everything is OK then run the code to process form
submission; if not - return user to the form and display error message.
this obviously requires that when a user is returned to the form all
entered values are re-populated.
i usually do this by:
a) defining <cfparam> at the top of the page for all form field values
b) setting initial <cfset err = 0> and <cfset errmsg = "">
c) during form validation i check each required field like <cfif
len(trim(form.firstname)) is 0><cfset err = 1><cfset errmsg = errmsg &
"Enter First Name!<br>"></cfif> - similar for all fields + validating
input on fields that require certain type of data (i.e.email address)
using isValid or regex
d) i put my submission processing code inside a <cfif err is 0>
e) above the <form> tag i have <cfif err gt 0><cfoutput>Please correct
the following errors:<br>#errmsg#</cfoutput></cfif>
f) each form field always has a value attribute which is set to
#form.formfieldname# (i.e. <input type="text" name="firstname"
value="#form.firstname#>
g) obviously, the <form>...</form> has to be inside <cfoutput>

hope this helps you

--

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Known Participant
April 5, 2007
Hi BKBK - sweet the form post my emails no but ....
when i have my javascript turned off and don't complete the 'orange' box the mail is still sent to me. same test place
http://www.healthhokkaido.com/files/contact_us.cfm

any ideas?
btw how did you find that error above?

Many thanks
Mark
BKBK
Community Expert
Community Expert
April 5, 2007
> btw how did you find that error above?
By submitting the form in your link (before you added the message field)

> when i have my javascript turned off and don't complete the
> 'orange' box the mail is still sent to me.

Not surprising. I do not see any Javascript code or anything about the 'orange' field that should stop mail from being sent.