Skip to main content
Participant
October 22, 2009
Question

cfform or cfmail troubles

  • October 22, 2009
  • 2 replies
  • 1178 views

I am lost, I am new to ColdFusion and am trying to create a "Contact Us" page. I have a form made up with all the fields that I need on the page. I want it to email the form to "email@mydomain.com" upon hitting submit. However I am stuck and cannot get the form to work properly. Can somebody, anybody help

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main-2-col.dwt.cfm" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Contact </title>
<meta name="keywords" content="emergency management, consultants" />
<meta name="description" content="Consultants" />
<meta name="robots" content="index,follow" />
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<link href="styles/styles-index.css" rel="stylesheet" type="text/css" />
<link href="styles/styles-index-col-table.css" rel="stylesheet" type="text/css" />
<link href="styles/styles-index-mobile.css" rel="stylesheet" media="handheld" type="text/css" />
<script type="text/javascript" src="/CFIDE/scripts/cfform.js"></script>
<script type="text/javascript" src="/CFIDE/scripts/masks.js"></script>
<script type="text/javascript">
<!--
    function  _CF_checkCFForm_1(_CF_this)
    {
        //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;

        //form element Name required check
        if( !_CF_hasValue(_CF_this['Name'], "TEXT", false ) )
        {
            _CF_onError(_CF_this, "Name", _CF_this['Name'].value, "Please enter your name.");
            _CF_error_exists = true;
        }

        //form element Phone required check
        if( !_CF_hasValue(_CF_this['Phone'], "TEXT", false ) )
        {
            _CF_onError(_CF_this, "Phone", _CF_this['Phone'].value, "Please enter your phone number.");
            _CF_error_exists = true;
        }

        //form element Email required check
        if( !_CF_hasValue(_CF_this['Email'], "TEXT", false ) )
        {
            _CF_onError(_CF_this, "Email", _CF_this['Email'].value, "Please enter your email.");
            _CF_error_exists = true;
        }

        //form element Answer required check
        if( _CF_hasValue(_CF_this['Answer'], "TEXT", false ) )
        {
            //form element Answer 'INTEGER' validation checks
            if (!_CF_checkinteger(_CF_this['Answer'].value, true))
            {
                _CF_onError(_CF_this, "Answer", _CF_this['Answer'].value, "Please enter the answer.");
                _CF_error_exists = true;
            }

        }else {
            _CF_onError(_CF_this, "Answer", _CF_this['Answer'].value, "Please enter the answer.");
            _CF_error_exists = true;
        }


        //display error messages and return success
        if( _CF_error_exists )
        {
            if( _CF_error_messages.length > 0 )
            {
                // show alert() message
                _CF_onErrorAlert(_CF_error_messages);
                // set focus to first form error, if the field supports js focus().
                if( _CF_this[_CF_FirstErrorField].type == "text" )
                { _CF_this[_CF_FirstErrorField].focus(); }

            }
            return false;
        }else {
            return true;
        }
    }
//-->
</script>
</head>

<body>
<!--- define the action page in the form tag. The form variables will
    pass to this page when the form is submitted --->


<a name="Top" id="Top"></a>
<div id="masthead"></div>
<div id="topnav">  <ul>
   <li><a href="index.cfm">Home</a></li>
  <li><a href="philosophy-mission.cfm">PHILOSOPHY & MISSION</a></li>
  <li><a href="services.cfm">SERVICES</a></li>
  <li><a href="contact.cfm">CONTACT</a></li>
  <li><a href="about-us.cfm">ABOUT US</a> </li>
  <li><a href="index.cfm">HOME</a></li
  </ul>
</div>
<div id="contentouter">
<div id="content"><!-- InstanceBeginEditable name="body" -->
  <div id="middlecontent">
    <h1>Contact Us</h1>
    <p>Phone: ###-###-####</p>
    <p>Postal:  </p>
    <hr />
    <h2>Information Request Form </h2>
        <div id="form">
                                <table width="90%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td>
                                            <p align="center">Please complete the fields below and we will respond to your inquiry within 48 hours.</p>
                                        </td>
                                    </tr>
                                </table>
                                <p></p>
                                <table width="90%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td>
                                            <p align="right">First Name:</p>
                                        </td>
                                        <td>
                                            <p><input type="text" name="First Name" /></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">Last Name:</p>
                                        </td>
                                        <td>
                                            <p><input type="text" name="Last Name" /></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">Address Street 1:</p>
                                        </td>
                                        <td>
                                            <p><input type="text" name="Address Street 1" size="30" /></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">Address Street 2:</p>
                                        </td>
                                        <td>
                                            <p><input type="text" name="Address Street 2" size="30" /></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">City:</p>
                                        </td>
                                        <td>
                                            <p><input type="text" name="City" /></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">Zip Code:</p>
                                        </td>
                                        <td>
                                            <p><input type="text" name="Zip Code" size="5" maxlength="5" /></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">State:</p>
                                        </td>
                                        <td>
                                            <p><select name="State">
                                                    <option value="AL">AL</option>
                                                    <option value="AK">AK</option>
                                                    <option value="AZ">AZ</option>
                                                    <option value="AR">AR</option>
                                                    <option value="CA">CA</option>
                                                    <option value="CO">CO</option>
                                                    <option value="CT">CT</option>
                                                    <option value="DE">DE</option>
                                                    <option value="DC">DC</option>
                                                    <option value="FL">FL</option>
                                                    <option value="GA">GA</option>
                                                    <option value="HI">HI</option>
                                                    <option value="ID">ID</option>
                                                    <option value="IL">IL</option>
                                                    <option value="IN">IN</option>
                                                    <option value="IA">IA</option>
                                                    <option value="KS">KS</option>
                                                    <option value="KY">KY</option>
                                                    <option value="LA">LA</option>
                                                    <option value="ME">ME</option>
                                                    <option value="MD">MD</option>
                                                    <option value="MA">MA</option>
                                                    <option value="MI">MI</option>
                                                    <option value="MN">MN</option>
                                                    <option value="MS">MS</option>
                                                    <option value="MO">MO</option>
                                                    <option value="MT">MT</option>
                                                    <option value="NE">NE</option>
                                                    <option value="NV">NV</option>
                                                    <option value="NH">NH</option>
                                                    <option value="NJ">NJ</option>
                                                    <option value="NM">NM</option>
                                                    <option value="NY">NY</option>
                                                    <option value="NC">NC</option>
                                                    <option value="ND">ND</option>
                                                    <option value="OH">OH</option>
                                                    <option value="OK">OK</option>
                                                    <option value="OR">OR</option>
                                                    <option value="PA">PA</option>
                                                    <option value="RI">RI</option>
                                                    <option value="SC">SC</option>
                                                    <option value="SD">SD</option>
                                                    <option value="TN">TN</option>
                                                    <option value="TX">TX</option>
                                                    <option value="UT">UT</option>
                                                    <option value="VT">VT</option>
                                                    <option value="VA">VA</option>
                                                    <option value="WA">WA</option>
                                                    <option value="WV">WV</option>
                                                    <option value="WI">WI</option>
                                                    <option value="WY">WY</option>
                                                </select></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">Daytime Phone:</p>
                                        </td>
                                        <td>
                                            <p><input type="text" name="Daytime Phone" /></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">Evening Phone:</p>
                                        </td>
                                        <td>
                                            <p><input type="text" name="Evening Phone" /></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">Email:</p>
                                        </td>
                                        <td>
                                            <p><input type="text" name="Email" /></p>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <p align="right">Comments:</p>
                                        </td>
                                        <td>
                                            <p><textarea name="Comments" cols="38"></textarea></p>
                                        </td>
                                    </tr>
                                </table>
                                <p><!--  submit button --><input type="submit" name="SubmitForm" value="Submit">
                                    <!-- reset button --> <input type="reset" name="ResetForm" value="Clear Form"></p>
                            </div>
  </div>
  <div id="rightcontent">
    <h2>Located where you and your business are.</h2>
    <p>Upon setting up a seminar date we will travel to your location. </p>
  </div></form>
<!-- InstanceEndEditable --></div>
<div id="contentpush"></div>
</div>
<div id="footer">
  <p><a href="#Top">Return to Top</a></p>
  <p><a href="index.cfm">Home</a> | <a href="philosophy-mission.cfm">Philosophy & Mission</a> |
    <a href="services.cfm">Services</a> | <a href="contact.cfm">Contact</a> | <a href="about-us.cfm">About Us</a> | <a href="index.cfm">Home</a></p>

</div>

</body>
</html>

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    October 24, 2009

    1) The Javascript tags suggest you want automatic validation for the form fields. The proper tag for this is <cfform>. Simply add the attributes 'required' to the input fields. Coldfusion would then automatically generate the Javascript for you.
    2) You should surround a comment in Coldfusion like this <!--- comment --->, not like this <!-- comment -->.
    3) Remove any redundant information.
    4) The cfmail tag will be in the action page which, in my example, is myActionPage.cfm.


    <html>
    <head>
    <title>Contact </title>
    <meta name="keywords" content="emergency management, consultants" />
    <meta name="description" content="Consultants" />
    <meta name="robots" content="index,follow" />
    <link href="styles/styles-index.css" rel="stylesheet" type="text/css" />
    <link href="styles/styles-index-col-table.css" rel="stylesheet" type="text/css" />
    <link href="styles/styles-index-mobile.css" rel="stylesheet" media="handheld" type="text/css" /> 
    </head>
    <body>
    <a name="Top" id="Top"></a>
    <div id="masthead"></div>
    <div id="topnav">  <ul>
       <li><a href="index.cfm">Home</a></li>
      <li><a href="philosophy-mission.cfm">PHILOSOPHY & MISSION</a></li>
      <li><a href="services.cfm">SERVICES</a></li>
      <li><a href="contact.cfm">CONTACT</a></li>
      <li><a href="about-us.cfm">ABOUT US</a> </li>
      <li><a href="index.cfm">HOME</a></li
      </ul>
    </div>
    <div id="contentouter">
    <div id="content">
      <div id="middlecontent">
        <h1>Contact Us</h1>
        <p>Phone: ###-###-####</p>
        <p>Postal:  </p>
        <hr />
        <h2>Information Request Form </h2>
            <div id="form">
                                    <table width="90%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td>
                                                <p align="center">Please complete the fields below and we will respond to your inquiry within 48 hours.</p>
                                            </td>
                                        </tr>
                                    </table>
                                    <!--- define the action page in the form tag. The form variables will
        pass to this page when the form is submitted --->
                                    <cfform action="myActionPage.cfm" method="post">
                                    <table width="90%" border="0" cellspacing="0" cellpadding="0">
                                        <tr>
                                            <td>
                                                <p align="right">First Name:</p>
                                            </td>
                                            <td>
                                                <p><cfinput type="text" name="FirstName" required="yes" message="Please enter your first name." /></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">Last Name:</p>
                                            </td>
                                            <td>
                                                <p><cfinput type="text" name="LastName" required="yes" message="Please enter your last name." /></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">Address Street 1:</p>
                                            </td>
                                            <td>
                                                <p><cfinput type="text" name="Address_Street_1" size="30" required="yes" message="Please enter your addres." /></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">Address Street 2:</p>
                                            </td>
                                            <td>
                                                <p><cfinput type="text" name="Address_Street_2" size="30" required="yes" message="" /></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">City:</p>
                                            </td>
                                            <td>
                                                <p><cfinput type="text" name="City" required="yes" message="Please enter your city." /></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">Zip Code:</p>
                                            </td>
                                            <td>
                                                <p><cfinput type="text" name="ZipCode" size="5" maxlength="5" required="yes" message="Please enter your zip code." /></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">State:</p>
                                            </td>
                                            <td>
                                                <p><cfselect name="State">
                                                        <option value="AL">AL</option>
                                                        <option value="AK">AK</option>
                                                        <option value="AZ">AZ</option>
                                                        <option value="AR">AR</option>
                                                        <option value="CA">CA</option>
                                                        <option value="CO">CO</option>
                                                        <option value="CT">CT</option>
                                                        <option value="DE">DE</option>
                                                        <option value="DC">DC</option>
                                                        <option value="FL">FL</option>
                                                        <option value="GA">GA</option>
                                                        <option value="HI">HI</option>
                                                        <option value="ID">ID</option>
                                                        <option value="IL">IL</option>
                                                        <option value="IN">IN</option>
                                                        <option value="IA">IA</option>
                                                        <option value="KS">KS</option>
                                                        <option value="KY">KY</option>
                                                        <option value="LA">LA</option>
                                                        <option value="ME">ME</option>
                                                        <option value="MD">MD</option>
                                                        <option value="MA">MA</option>
                                                        <option value="MI">MI</option>
                                                        <option value="MN">MN</option>
                                                        <option value="MS">MS</option>
                                                        <option value="MO">MO</option>
                                                        <option value="MT">MT</option>
                                                        <option value="NE">NE</option>
                                                        <option value="NV">NV</option>
                                                        <option value="NH">NH</option>
                                                        <option value="NJ">NJ</option>
                                                        <option value="NM">NM</option>
                                                        <option value="NY">NY</option>
                                                        <option value="NC">NC</option>
                                                        <option value="ND">ND</option>
                                                        <option value="OH">OH</option>
                                                        <option value="OK">OK</option>
                                                        <option value="OR">OR</option>
                                                        <option value="PA">PA</option>
                                                        <option value="RI">RI</option>
                                                        <option value="SC">SC</option>
                                                        <option value="SD">SD</option>
                                                        <option value="TN">TN</option>
                                                        <option value="TX">TX</option>
                                                        <option value="UT">UT</option>
                                                        <option value="VT">VT</option>
                                                        <option value="VA">VA</option>
                                                        <option value="WA">WA</option>
                                                        <option value="WV">WV</option>
                                                        <option value="WI">WI</option>
                                                        <option value="WY">WY</option>
                                                    </cfselect></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">Daytime Phone:</p>
                                            </td>
                                            <td>
                                                <p><cfinput type="text" name="Daytime_Phone" required="yes" message="Please enter your daytime phone number." /></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">Evening Phone:</p>
                                            </td>
                                            <td>
                                                <p><cfinput type="text" name="Evening_Phone" required="yes" message="" /></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">Email:</p>
                                            </td>
                                            <td>
                                                <p><cfinput type="text" name="Email" required="yes" message="Please enter your email address." /></p>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <p align="right">Comments:</p>
                                            </td>
                                            <td>
                                                <p><cftextarea name="Comments" cols="38"></cftextarea></p>
                                            </td>
                                        </tr>
                                    </table>
                                    <p><!---  submit button ---><cfinput type="submit" name="SubmitForm" value="Submit">
                                        <!--- reset button ---> <cfinput type="reset" name="ResetForm" value="Clear Form"></p>
                                </div>
      </div>
      <div id="rightcontent">
        <h2>Located where you and your business are.</h2>
        <p>Upon setting up a seminar date we will travel to your location. </p>
      </div></cfform>
    <!---InstanceEndEditable---></div>
    <div id="contentpush"></div>
    </div>
    <div id="footer">
      <p><a href="#Top">Return to Top</a></p>
      <p><a href="index.cfm">Home</a> | <a href="philosophy-mission.cfm">Philosophy & Mission</a> |
        <a href="services.cfm">Services</a> | <a href="contact.cfm">Contact</a> | <a href="about-us.cfm">About Us</a> | <a href="index.cfm">Home</a></p>
    </div>
    </body>
    </html>

    Inspiring
    October 22, 2009

    Your "form" doesn't have any <form> tags around it.  So really it's not a form but a bunch of <input> tags.  Looks the same, but dun't work the same.

    Also, for the form to be emailed, you do need an action page that performs the <cfmail>.

    There's a section on form handling in the CF docs.  Probably worth a read:

    http://livedocs.adobe.com/coldfusion/8/htmldocs/formatData_01.html

    And for emailing:

    http://livedocs.adobe.com/coldfusion/8/htmldocs/email_01.html

    And if you're new to CF, read the first five (bare minimum) chapters here:

    http://livedocs.adobe.com/coldfusion/8/htmldocs/Part_4_CF_DevGuide_1.html

    And at least scan the tag & function reference here:

    http://livedocs.adobe.com/coldfusion/8/htmldocs/Part_3_CFML_Ref_1.html

    --

    Adam

    Participant
    October 22, 2009

    Thanks "A"

    I am about to head offline for the night but I will def give those a look over in the Morning. Any other help is always appreciated as I read up on this. Thanks guys.