Solved

Help with cfform validation

Posted on 2011-03-02
6
983 Views
Last Modified: 2012-05-11
I have a registration process that loops through different options to present them to the user for selection of either "Yes" or "No" in a cfform.  The code is attached below.

Some details:
option_id is an integer

The problem I'm having is that even if I select "Yes" or "No" from the item list, the coldfusion keeps throwing an alert at me "You must select an answer for each addon group."  I don't know why it won't validate this form.  

I have attached my code as well as the code coldfusion outputs to validate the form when the site is live.  The form field in question is numbered "1" for the option_id.  Any ideas?

Thanks.
<script type="text/javascript">
<!--
    _CF_checkCFForm_1 = function(_CF_this)
    {
        //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;


        //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>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['mailingemail']=true;
/* ]]> */</script>
<script type="text/javascript">
<!--
    _CF_checkCFForm_2 = function(_CF_this)
    {
        //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;

        //form element mailingemail required check
        if( _CF_hasValue(_CF_this['mailingemail'], "TEXT", false ) )
        {
            //form element mailingemail 'EMAIL' validation checks
            if (!_CF_checkEmail(_CF_this['mailingemail'].value, true))
            {
                _CF_onError(_CF_this, "mailingemail", _CF_this['mailingemail'].value, "Invalid Email Address.  Please try again.");
                _CF_error_exists = true;
            }

        }else {
            _CF_onError(_CF_this, "mailingemail", _CF_this['mailingemail'].value, "Invalid Email Address.  Please try again.");
            _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>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['division_selected']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['division_selected']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['division_selected']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['division_selected']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['division_selected']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['1']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['1']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['payment_method']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['payment_method']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['payment_amount']=true;
/* ]]> */</script>

<script type="text/javascript">/* <![CDATA[ */
	if (window.ColdFusion) ColdFusion.required['Agree']=true;
/* ]]> */</script>
<script type="text/javascript">
<!--
    _CF_checkCFForm_3 = function(_CF_this)
    {
        //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element 1 required check
        if( !_CF_hasValue(_CF_this['1'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "1", _CF_this['1'].value, "You must select an answer for each open addon group.");
            _CF_error_exists = true;
        }

        //form element 1 required check
        if( !_CF_hasValue(_CF_this['1'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "1", _CF_this['1'].value, "You must select an answer for each open addon group.");
            _CF_error_exists = true;
        }

        //form element payment_method required check
        if( !_CF_hasValue(_CF_this['payment_method'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "payment_method", _CF_this['payment_method'].value, "Please indicate your payment method.");
            _CF_error_exists = true;
        }

        //form element payment_method required check
        if( !_CF_hasValue(_CF_this['payment_method'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "payment_method", _CF_this['payment_method'].value, "Please indicate your payment method.");
            _CF_error_exists = true;
        }

        //form element payment_amount required check
        if( !_CF_hasValue(_CF_this['payment_amount'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "payment_amount", _CF_this['payment_amount'].value, "Please indicate your payment amount.");
            _CF_error_exists = true;
        }

        //form element Agree required check
        if( !_CF_hasValue(_CF_this['Agree'], "CHECKBOX", false ) )
        {
            _CF_onError(_CF_this, "Agree", _CF_this['Agree'].value, "Please Read and Agree to the Commitments.");
            _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>

Open in new window

<cfquery datasource="#db_source#" name="getaddons">select * from user_registration_options where option_fee_id = #fc# and option_eligibility = 'Open'</cfquery>
<cfif getaddons.recordcount gt 0>
   <cfloop query="getaddons"><tr>
           <td class="accounttd" width="40%">Item:<strong>#option_title#</strong><br /></td>
           <td valign="top" class="account_notify">		   
             <strong>Would you like to register for this add on?</strong>
            <cfinput type="radio" name="#option_id#" value="Yes" required="no" message="You must select an answer for each addon group." />Yes
               <cfinput type="radio" name="#option_id#" value="No" required="no" message="You must select an answer for each addon group." />No</div></td>
         </tr></cfloop>
		 <cfelse>
		           <tr> <td colspan="2" class="accounttd">There are no "open" addons for this registration item.  No selection is needed.</td></tr>
		 </cfif>

Open in new window

0
Comment
Question by:Eduski
[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
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:onlyamir007
ID: 35024316
try this .....

are you validating these radio??? or anything else???
<cfquery datasource="#db_source#" name="getaddons">select * from user_registration_options where option_fee_id = #fc# and option_eligibility = 'Open'</cfquery>
<cfif getaddons.recordcount gt 0>
   <cfloop query="getaddons"><tr>
           <td class="accounttd" width="40%">Item:<strong>#option_title#</strong><br /></td>
           <td valign="top" class="account_notify">		   
             <strong>Would you like to register for this add on?</strong>
            <cfinput type="radio" name="#option_id#" value="Yes"  />Yes
               <cfinput type="radio" name="#option_id#" value="No"  />No</div></td>
         </tr></cfloop>
		 <cfelse>
		           <tr> <td colspan="2" class="accounttd">There are no "open" addons for this registration item.  No selection is needed.</td></tr>
		 </cfif>

Open in new window

0
 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 35024367
By default, required attribute in cfinput is no, so you don't really need to specify it..

<cfinput type="radio" name="#option_id#" value="Yes" required="no" message="You must select an answer for each addon group.">Yes
<cfinput type="radio" name="#option_id#" value="No" required="no" message="You must select an answer for each addon group.">No

Don't enter  "/>" end tag in your cfinput... they have the same name...
0
 
LVL 3

Author Comment

by:Eduski
ID: 35025522
Thanks for your replies.  Neither of those suggestions achieved my desired effect.  I need the form to validate each radio group in the loop, but for some reason it keeps asking even when a selection in that group is made.  The code outputs in the browser as follows (attached). and the form validation is as follows (attached).  Thanks for your help.
<script type="text/javascript">
<!--
    _CF_checkCFForm_3 = function(_CF_this)
    {
        //reset on submit
        _CF_error_exists = false;
        _CF_error_messages = new Array();
        _CF_error_fields = new Object();
        _CF_FirstErrorField = null;

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element division_selected required check
        if( !_CF_hasValue(_CF_this['division_selected'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "division_selected", _CF_this['division_selected'].value, "You must select a division/age group.");
            _CF_error_exists = true;
        }

        //form element 1 required check
        if( !_CF_hasValue(_CF_this['1'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "1", _CF_this['1'].value, "You must select an answer for each open addon group.");
            _CF_error_exists = true;
        }

        //form element 1 required check
        if( !_CF_hasValue(_CF_this['1'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "1", _CF_this['1'].value, "You must select an answer for each open addon group.");
            _CF_error_exists = true;
        }

        //form element payment_method required check
        if( !_CF_hasValue(_CF_this['payment_method'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "payment_method", _CF_this['payment_method'].value, "Please indicate your payment method.");
            _CF_error_exists = true;
        }

        //form element payment_method required check
        if( !_CF_hasValue(_CF_this['payment_method'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "payment_method", _CF_this['payment_method'].value, "Please indicate your payment method.");
            _CF_error_exists = true;
        }

        //form element payment_amount required check
        if( !_CF_hasValue(_CF_this['payment_amount'], "RADIO", false ) )
        {
            _CF_onError(_CF_this, "payment_amount", _CF_this['payment_amount'].value, "Please indicate your payment amount.");
            _CF_error_exists = true;
        }

        //form element Agree required check
        if( !_CF_hasValue(_CF_this['Agree'], "CHECKBOX", false ) )
        {
            _CF_onError(_CF_this, "Agree", _CF_this['Agree'].value, "Please Read and Agree to the Commitments.");
            _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>

Open in new window

<form name="CFForm_3" id="CFForm_3" action="account_register.cfm?fc=1" method="post" onsubmit="return _CF_checkCFForm_3(this)">
           <td valign="top" class="account_notify">		   
             <div align="right"><strong>Would you like to register for this add on?</strong>
  <input name="1" id="1"  type="radio" value="Yes" />Yes
  <input name="1" id="1"  type="radio" value="No" />No</div></td>
</form>

Open in new window

0
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
LVL 11

Expert Comment

by:Brijesh Chauhan
ID: 35025619
You can try using JS and input type..

here is a similar question on EE on how to do it..

http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_20742824.html
0
 
LVL 11

Accepted Solution

by:
Brijesh Chauhan earned 500 total points
ID: 35025669
okay.. did a small test, the problem seems to be your numeric field names, name="1", i changed the name to name="Field_1" and it works now..check it out...

<cfform action="" method="post">
           <td valign="top" class="account_notify">		   
             <div align="right"><strong>Would you like to register for this add on?</strong>
  <cfinput name="Field_1" id="1"  type="radio" value="Yes" required="yes" message="You must select an answer for each addon group.">Yes
  <cfinput name="Field_1" id="1"  type="radio" value="No" required="yes" message="You must select an answer for each addon group.">No</div></td>
  <input type="submit" name="submit" value="submit">
</cfform>

Open in new window

0
 
LVL 3

Author Closing Comment

by:Eduski
ID: 35025690
I wonder why this is...
0

Featured Post

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to count occurrences of each item in an array.

688 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