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

BKBK
Community Expert
Community Expert
April 5, 2007
Variable CONTACTMESSAGE is undefined.
The error occurred in C:\Sites\Accounts\bimfire\healthhokkaido.com\www\files\navtemp.cfm: line 64
62 : <!--- Send the message to yourself, when the user posts it on your site. --->
63 : <CFMAIL to="holloway@healthhokkaido.com" from="#ContactEmail#" Subject="Contact From healthhokkaido.com">
64 : #ContactMessage#


Include in the form

Message: <input type="text" class="txtBoxes" name="ContactMessage"><br>
<input type="hidden" name="ContactMessage_required" value="Please Enter A Message.">


Known Participant
April 5, 2007
Jezz BKBK I must be a dummy (don't hafta answer)

Im using the following code but now the email doen't arrive in my inbox
sapporomark@yahoo.com is my email --soo sorry for taking up your time -- would you mind having one more look -- the test page is at
http://www.healthhokkaido.com/files/contact_us.cfm

form
<CFIF IsDefined("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="contact_us.cfm" method="post"></cfoutput>
<input type="hidden" name="Process" Value="1">
Name: <input type="text" class="txtBoxes" name="ContactName"><br>
E-mail: <input type="text" class="txtBoxes" name="ContactEmail"><br>
<input type="hidden" name="ContactName_required" value="Please Enter Your Name!">
<input type="hidden" name="ContactEmail_required" value="Please Enter Your Email Address!">
<script src="foil.js" type="text/JavaScript"></script>
<noscript>
<td>Enter 'orange' here:</td>
<td><input name='foil'/></td>
</noscript>
<br><br>
<input type="submit" id="butComment" value="Send">
</form></cfif>

foil.js
// JavaScript Document
document.write("<input name='foil' type='hidden' value='orange' />");
document.write('If you can read this, then Javascript is enabled in the browser');

Thanks for all your help
BKBK
Community Expert
Community Expert
April 5, 2007
> I tried this one but got an error after the form code

You forgot the cfif end tag. Put </form></cfif> in place of </form>.


BKBK
Community Expert
Community Expert
April 5, 2007
>in your example what does #cgi.script_name# do?

See for yourself. Run

<cfoutput>#cgi.script_name#<cfoutput>

It is a self-reference path to the current page. That is, it makes the form submit to the form's page. Cgi.script_name is convenient for testing examples like the one I gave.

> do i still use this above the form?

> <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">
etc., etc.


Yes, with form in place of cfform

Known Participant
April 4, 2007

HI I tried this one but got an error after the form code...>

<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!">

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: <input type="text" class="txtBoxes" name="ContactName"><br>
E-mail: <input type="text" class="txtBoxes" name="ContactEmail"><br>
<input type="hidden" name="ContactName_required" value="Please Enter Your Name!">
<input type="hidden" name="ContactEmail_required" value="Please Enter Your Email Address!">
<script src="foil.js" type="text/JavaScript"></script>
<noscript>
<td>We're now inside &lt;noscript&gt; tag. Enter 'orange' here:</td>
<td><input name="foil" type="Hidden"/></td>
</noscript>
<br><br>
<input type="submit" id="butComment" value="Send">
</form>

Context validation error for tag CFIF.
The start tag must have a matching end tag. An explicit end tag can be provided by adding </CFIF>. If the body of the tag is empty you can use the shortcut <CFIF .../>.
ERROR

The error occurred in C:\Sites\Accounts\bimfire\healthhokkaido.com\www\files\contact_us.cfm: line 14

12 :
13 :
14 : <CFIF IsDefined("process")>
15 :
16 : <!--- Send the message to yourself, when the user posts it on your site. --->
Known Participant
April 4, 2007
Hi many thanks in your example what does #cgi.script_name# do?
do i still use this above the form?

<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>
BKBK
Community Expert
Community Expert
April 4, 2007
Quiero Mas,

There are some issues. First, the usual way is to introduce the noscript tag right after the script tag, thus

<script>
</script>
<noscript>
</noscript>

You cannot get this in your code. Cfform will automatically write several script tags at the top of the page. There will therefore be HTML stuff between the script tag(s) and your noscript tag. The way out is to use form and input tags instead.

Here is an example. If you disable scripting in the browser, you should access the contents of the noscript tag.

foil.js
========
document.write('If you can read this, then Javascript is enabled in the browser');

testPage.cfm
=============
<cfoutput><form action="#cgi.script_name#" method="post"></cfoutput>
<input type="hidden" name="Process" Value="1">
Name: <input type="text" class="txtBoxes" name="ContactName"><br>
E-mail: <input type="text" class="txtBoxes" name="ContactEmail"><br>
<input type="hidden" name="ContactName_required" value="Please Enter Your Name!">
<input type="hidden" name="ContactEmail_required" value="Please Enter Your Email Address!">
<script src="foil.js" type="text/JavaScript"></script>
<noscript>
<td>We're now inside &lt;noscript&gt; tag. Enter 'orange' here:</td>
<td><input name="foil" type="Hidden"/></td>
</noscript>
<br><br>
<input type="submit" id="butComment" value="Send">
</form>

Participating Frequently
April 4, 2007
You didn't specify what isn't working.

If you want to stop the submission, you have to return false with the function being called.

Try putting some simple debug statements in the jsAC() function such as an alert, to let you know that the routine is being called.