|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
You don't need a fax machine to get faxes. Get a fax-to-email fax number from CallWave. Try it free.
|
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Quote:
Thank you! I'll go try this... Jel ![]() |
|
#4
|
||||
|
||||
|
<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 |
|
#5
|
|||
|
|||
|
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="javascript FUNCTION);"> |
|
#6
|
|||
|
|||
|
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 ![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > CF Form Validation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|