[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Help with cfform validation

Posted on 2011-03-02
6
Medium Priority
?
986 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
Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

 
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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Suggested Courses

649 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