?
Solved

Help with cfform validation

Posted on 2011-03-02
6
Medium Priority
?
985 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
Docker-Compose to Simplify Multi-Container Builds

Our veteran DevOps Author takes you through how to build a multi-container environment, managed with a single utility in order to simplify your deployments.

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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

765 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