Solved

Help with cfform validation

Posted on 2011-03-02
6
975 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
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:onlyamir007
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 11

Expert Comment

by:Brijesh Chauhan
Comment Utility
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
Comment Utility
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
Comment Utility
I wonder why this is...
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Conditional Link URL - Easy Question 4 43
Pick image, show data 4 33
Import csv files to MS SQL 5 60
Select2 jquery help 9 41
Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now