ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
  #1  
Old August 24th, 2004, 06:42 AM
mb5 mb5 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 mb5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
CF Form Validation

Hi All,

Im new to CF and am wondering is there an easy way to validate forms?
I have tried numerous tutorials and vain, and found one site that said CF and Javascript were incompatable! is this true??

I tried the following:
<cfinput type="Text" name="userName" message="Please enter your name." required="Yes">

and while it worked for one of the elements it failed to work on the other 5!

I have also tried simple javascript (which worked for another PHP project) also in vain!

I have changed my code so many times, its wrecking my head!

Is there any EASY way to validate forms????

Thanks
Jel

Reply With Quote
  #2  
Old August 24th, 2004, 08:21 AM
kiteless kiteless is offline
Moderator
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,491 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 3 Days 18 h 21 m 26 sec
Reputation Power: 42
Whoever said that CF and Javascript are "incompatible" is not only totally wrong, but they clearly have no idea what either Javascript or ColdFusion do. I would never listen to anything that person/site has to say again because they might as well have said that the Earth is flat.

Look in the CF documentation, the <cfinput> tag has built-in Javascript generation for form field validation, or you can specify your own Javascript. Or you can bypass <cfform> and <cfinput> completely and just use regular form fields and use whatever Javascript validation you want.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old August 24th, 2004, 08:59 AM
mb5 mb5 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 2 mb5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Smile

Quote:
Originally Posted by kiteless
Whoever said that CF and Javascript are "incompatible" is not only totally wrong, but they clearly have no idea what either Javascript or ColdFusion do. I would never listen to anything that person/site has to say again because they might as well have said that the Earth is flat.

Look in the CF documentation, the <cfinput> tag has built-in Javascript generation for form field validation, or you can specify your own Javascript. Or you can bypass <cfform> and <cfinput> completely and just use regular form fields and use whatever Javascript validation you want.


Thank you! I'll go try this... Jel

Reply With Quote
  #4  
Old August 26th, 2004, 10:18 AM
Alas's Avatar
Alas Alas is offline
Wickedwd.com
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: wickedwd.com
Posts: 182 Alas Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 16 h 41 m 17 sec
Reputation Power: 0
Thumbs up Validating in <CFFORM> is Cake

<cfinput type="Text"
name="userName"
message="Please enter your name."
required="Yes">

just add validate="Alas"

obviously replace Alas with what you want to validate, telephone, socialsecurity, integer, float, etc.

Dont want to condecend you, but just in case heres an example

Code:
<cfinput 
        name="socialsecurityofuser" 
        size="9"
        required="Yes"
        maxlength="11"
        validate="social_security_number"
        message="Please enter your social security number."
        value="Initial value of textbox">


-Alas

Reply With Quote
  #5  
Old October 1st, 2004, 06:47 PM
z44sms z44sms is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 9 z44sms User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Im new to CF and am wondering is there an easy way to validate forms?
I have tried numerous tutorials and vain, and found one site that said CF and Javascript were incompatable! is this true??

I tried the following:
<cfinput type="Text" name="userName" message="Please enter your name." required="Yes">

NO you can use Javascript my co-worker uses javascript to much
I get mad at him because damn guys making more code then is needed only time I really ever needed it was when we wanted popup windows for validating a form... but you just make your java code then you can do calls right in the god forsaking HTML. Don't believe them COLDFUSION can be even seperate from HTML if you wanted ...
the next line could be totally HTML/JAVA nothing to do with COLDFUSION in the SCRIPT except this OUTPUT.
<CFOUTPUT> #MONKEY# </CFOUTPUT>
<SOMEHTML onmouse="javascriptFUNCTION);">

Reply With Quote
  #6  
Old November 6th, 2004, 05:22 AM
PArky PArky is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2004
Posts: 2 PArky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is what I use atm.
Code:
<cfscript>
function validate_email(str,field) {
	ret = "true";
	if( not len(trim(arguments.str)) or not refind("^[0-9A-Za-z.'+_-]+@([0-9A-Za-z-]+\.)+[A-Za-z]+$", trim(arguments.str)) ) {
		ret = "false";
		WriteOutput("#arguments.field# is onjuist.");
	}
	return ret;
}

function validate_string(str, field) {
	ret = "true";
	if( not len(trim(arguments.str)) or refind("[!-+:-@{-~./\^ ]", trim(arguments.str))) {
		ret="false"; 
		WriteOutput("#arguments.field# is onjuist");
		}
	return ret;
}

function validate_name(str, field) {
	ret = "true";
	if( not len(trim(arguments.str)) or refind("[!-+:-@{-~[-_/]", trim(arguments.str))) {
		ret="false";
		WriteOutput("#arguments.field# is onjuist");
	}
	return ret;
}

function validate_address(str, field) {
	ret = "true";
	if( not len(trim(arguments.str)) or not refind("^[0-9A-Za-z]+ ([0-9])", trim(arguments.str))){ 
		ret="false";
		WriteOutput("#arguments.field# is onjuist");
	}
	return ret;
}
</cfscript>

<cfif NOT validate_string(form.username,"Gebruikersnaam")><br></cfif>  
<cfif NOT validate_string(form.password,"Paswoord") ><br></cfif>
<cfif NOT validate_name(form.firstname,"Voornaam")><br></cfif> 
<cfif NOT validate_name(form.lastname,"Naam")><br></cfif>
<cfif NOT validate_name(form.province,"Provincie")><br></cfif>
<cfif NOT validate_name(form.city,"Gemeente")><br></cfif>
<cfif NOT validate_address(form.address1, "Adres 1")><br></cfif>
<cfif NOT (len(trim(form.address2)) AND validate_address(form.address2, "Adres 2"))><br></cfif>
<cfif NOT validate_email(form.emailaddress,"E-Mail")><br></cfif>
ect....


validate_email u know what it's for I suggest.
validate_string : usernames and passes allow a-z A-Z 0-9 _ [ ] -
validate_name : names of people or cities allow a-z A-Z 0-9 . -
validate_address : a word and a number: "foostreet 52"

the functions take a field parameter so it generates an error with the name you displayed on your form.


I am not sure they FULLY work because it takes time to find more bugs in them tho I have spent a hour straight debugging and testing these functions.

if you don't understand the stuff between refind, search an ASCCI table

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > CF Form Validation


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway