?
Solved

Form validation

Posted on 2005-05-16
14
Medium Priority
?
153 Views
Last Modified: 2013-12-24
Hi Experts

I have a form with fields I need to validate based on the users selection like so.

The fields involved are E12, E13, E14 and E15.

The logic needs to be

 E12 = 02 or 05, E13 needs to be 98, E14 needs to be 99, E15 needs to be 99.

 E12 = 04, E13 needs to be 03, E14 needs to be 01, 02, 03, 04, 05, E15 needs to be 99.

 E12 = 03, E13 needs to be 01 or 02, E14 needs to be 99, E15 needs to be 02.

 E12 = 01 E13 needs to be 01 or 02, E14 needs to be 99, E15 needs to be 01, 02, 03.

Any 1 of the above is valid and the form should be submitted anything else should be thrown back with an error message.

I previously submitted this problem and got a good solution but I assumed I would be able to nest this solution in order to expand it and cover all the options this gave me a very obscure error message.

Previous question
http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21422294.

So I am reposting in the hope someone can help as I am running out of time and finding this the hardest part of my application.

Any help would be greatly appreciated.

Thanks

Clive
html
0
Comment
Question by:clivecrawdevil
  • 7
  • 7
14 Comments
 
LVL 9

Expert Comment

by:cyberdevil67
ID: 14009593
This is off the top of my head.

<cfset Contine = false>
<cfswitch expression="#E12#">
 <cfcase value="02,05" delimiters=",">
  <cfif e13 eq 98 and e14 eq 99 and e15 eq 99>
            <cfset Contine = true>
      </cfif>
 </cfcase>
 <cfcase value="04">
      <cfif e13 eq 3 and "01,02,03,04,05" contains e14 and e15 eq 99>
            <cfset Contine = true>
      </cfif>
 </cfcase>
 <cfcase value="03">
            <cfif (e13 eq 01 or e13 eq 02) and e14 eq 99 and e15 eq 02>
                  <cfset Contine = true>
            </cfif>
 </cfcase>
 <cfcase value="01">
            <cfif (e13 eq 01 or e13 eq 02) and e14 eq 99 and "01,02,03" contains e15>
                  <cfset Contine = true>
            </cfif>
 </cfcase>

</cfswitch>
0
 

Author Comment

by:clivecrawdevil
ID: 14009667
Hi Cyberdevil67

Getting this error String index out of range: -2

same as when i nested if statements in my previouse attempt

http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21422294

any idea what this message means?

Clive
0
 
LVL 9

Expert Comment

by:cyberdevil67
ID: 14009686
That link doesn't exist anymore.

Which line is erroring
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 9

Expert Comment

by:cyberdevil67
ID: 14009736
which version of coldfusion are you using?
0
 

Author Comment

by:clivecrawdevil
ID: 14009741
Sorry my bad.

http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21422294.html

think the link was broken because it was missing html extenstion.

That is the entire error message. Even with robust exception and debugging enabled.
0
 

Author Comment

by:clivecrawdevil
ID: 14009743
MX 7
0
 
LVL 9

Accepted Solution

by:
cyberdevil67 earned 2000 total points
ID: 14009753
This works for me

<cfparam name="E12" default="05">
<cfparam name="E13" default="98">
<cfparam name="E14" default="99">
<cfparam name="E15" default="99">

<cfset Contine = false>
<cfswitch expression="#E12#">
      <cfcase value="02,05" delimiters=",">
            <cfif e13 eq 98 and e14 eq 99 and e15 eq 99>
                  <cfset Contine = true>
            </cfif>
      </cfcase>
      <cfcase value="04">
            <cfif e13 eq 3 and "01,02,03,04,05" contains e14 and e15 eq 99>
                  <cfset Contine = true>
            </cfif>
      </cfcase>
      <cfcase value="03">
            <cfif (e13 eq 01 or e13 eq 02) and e14 eq 99 and e15 eq 02>
                   <cfset Contine = true>
            </cfif>
      </cfcase>
      <cfcase value="01">
            <cfif (e13 eq 01 or e13 eq 02) and e14 eq 99 and "01,02,03" contains e15>
                  <cfset Contine = true>
            </cfif>
      </cfcase>
</cfswitch>

<cfdump var="#Contine#">
0
 

Author Comment

by:clivecrawdevil
ID: 14009873
This was the return when i put it in with my code.


false





Error Occurred While Processing Request  
String index out of range: -2  
 
 
Please try the following:
Enable Robust Exception Information to provide greater detail about the source of errors. In the Administrator, click Debugging & Logging > Debugging Settings, and select the Robust Exception Information option.
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.

 
Browser   Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)
Remote Address   192.168.0.24
Referrer    
Date/Time   16-May-05 02:04 PM
 
 
0
 
LVL 9

Expert Comment

by:cyberdevil67
ID: 14009903
Have you got robust Excpetion switch on?

I tested the code I posted on MX 7.0 running here on windows XP, and Windows Server 2000, and Windows Server 2003 and it works.

If you are getting the false then the problem is further in the code. by switching on the robust Excpetion it will give you more detailed info.
0
 

Author Comment

by:clivecrawdevil
ID: 14009907
Could it be the way i am implementing the code?

I have this sitting above my insert query, so if it checks out ok the record is saved to the database.
0
 
LVL 9

Expert Comment

by:cyberdevil67
ID: 14009941
Do the switch Robust Exception on in the debbuging like the error message tells you to do.
0
 

Author Comment

by:clivecrawdevil
ID: 14009983
Got it was a problem with the primary key.

Thanks alot thats great, works well.

Just one more question if you have time, how would i show the error?

Would i put it in <cfset Contine = false> or would it be better to use a cflocation to redirect to an error page?

Clive

0
 
LVL 9

Expert Comment

by:cyberdevil67
ID: 14009999
<cfif Contine>
 Insert into database
<cfelse>
 Display Error
</cfif

yes you could do relocation if you want.
0
 

Author Comment

by:clivecrawdevil
ID: 14010055
Excelent

Thanks alot cyberdevil!

Points well deserved.

Clive
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month17 days, 13 hours left to enroll

830 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