Form Validation-Client and Server - PowerPoint PPT Presentation

About This Presentation
Title:

Form Validation-Client and Server

Description:

May be defeated by disabling JS in browser. Poses risks but convenient. Saves server load ... Safer but less convenient. Client validation. CFFORM. Writes ... – PowerPoint PPT presentation

Number of Views:25
Avg rating:3.0/5.0
Slides: 12
Provided by: JonBru3
Category:

less

Transcript and Presenter's Notes

Title: Form Validation-Client and Server


1
Form Validation-Client and Server
  • Verifying your visitors form submissions
  • Jon Brundage
  • CF developer/Section 508/web accessibility
  • Jonwind_at_windcompany.com

2
Why validate?
  • Safety
  • protects your database and site
  • Better user experience
  • Makes your site more professional
  • Saves time
  • Less submits and page calls

3
Two types of Validation
  • Client
  • Via Scripting
  • Javascript most common
  • May be defeated by disabling JS in browser
  • Poses risks but convenient
  • Saves server load
  • Server
  • Via CGI/ASP etc
  • This discussion focuses on the power of CF
  • Cant be defeated by changes in browser settings
  • Safer but less convenient

4
Client validation
  • CFFORM
  • Writes Javascript validation for you
  • CFINPUT tag
  • http//www.macromedia.com/support/coldfusion/ts/do
    cuments/cfform_hotfix.htm hotfix for CFMX 6.1
  • Javascript
  • Write your own
  • Many free scripts available on the Web
  • http//webdeveloper.earthweb.com/webjs/
  • http//www.jsmadeeasy.com/
  • http//www.js-examples.com/js/
  • http//www.dynamicdrive.com/ (DHTML)

5
Test for state of scripting on client
  • Inside the FORM tag, add a NOSCRIPT tag with a
    hidden form field
  • ltnoscriptgt
  • ltinput type"hidden" name"scriptOff"
    value"scriptOff"gt
  • lt/noscriptgt
  • Use Isdefined(form.scriptOff) in action page with
    a CFIF tag to determine if you need to apply
    server side validation.

6
Server validation
  • CF functions
  • CF tags
  • CF custom tags- developers exchange
  • CF structures and arrays

7
CF STRUCTURE
  • Contain variables called keys
  • Create with a CFSET statement
  • ltcfset formerrorsstructnew()gt
  • A structure with elements contained in it will
    have a count similar to query recordcount
  • ltcfif structcount(formerrors) gt "0"gt

8
CF STRUCTURE cont.
  • Structures may be looped.
  • ltcfloop collectionformerrors item"ErrorType"gt
  • ltul class"list"gt
  • ltli style"color FF0000"gt
  • formErrorserrorType
  • lt/ligt
  • lt/ulgt
  • lt/cfloopgt

9
Using a structure to hold errors
  • ltcfset formerrorsstructnew()gt
  • as errors encountered, add to structure
  • ltcfset tempstructinsert(formerrors,"ErroruserFirs
    t","You failed to enter your first name."
    ,"yes")gt
  • At the end of processing form errors, display by
    looping over the structure
  • ltcfloop collectionformerrors item"ErrorType"gt
  • ltul class"list"gt
  • ltli style"color FF0000"gt
  • formErrorserrorType
  • lt/ligt
  • lt/ulgt
  • lt/cfloopgt

10
Make use of CF functions
  • IsNumeric
  • Verify numeric fields
  • Findoneof
  • Look at characters
  • And others!
  • Use you creativity.

11
THANK YOU
  • Remember, CF has many tools at your disposal.
  • Have fun, be creative and dont worry too much
    about being right
  • Many ways to solve problems.
  • Questions/comments-
  • Jonwind_at_windcompany.com
Write a Comment
User Comments (0)
About PowerShow.com