derrick rapley [email protected] maryland cfug october 8, 2002

11
<cf_datavalidate> Derrick Rapley [email protected] Maryland CFUG October 8, 2002

Upload: anis-barnett

Post on 26-Dec-2015

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

<cf_datavalidate>

Derrick Rapley

[email protected]

Maryland CFUG

October 8, 2002

Page 2: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

Agenda What is cf_datavalidate? Why use server-side validation? How to use cf_datavalidate

Syntax Displaying Error Messages Using Custom Validation

Page 3: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

What is cf_datavalidate? cf_datavalidate is a custom tag that performs

server-side data validation Requires use of child tag cf_dataValidateItem Easy to use Minimizes the amount of code needed to perform

validation Keeps track of error messages Handle custom validation

Page 4: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

Why use server-side validation? To prevent potential malicious attacks To prevent bad data from being entered

into the database Client side validation is useless when

JavaScript is turned off. (including CFFORM)

Page 5: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

cf_datavalidate cf_datavalidate is the parent tag Must have end tag Requires two parameters

1. OUTPUT (required) – the variable you want the error messages stored in

2. TYPE (optional) – the type of variable for OUTPUT, QUERY or STRUCTURE (default is QUERY)

<cf_datavalidate output="qryErrors" type="structure"><cf_dataValidateItem>

</cf_datavalidate>

Page 6: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

cf_dataValidateItem Must be encapsulated by cf_datavalidate<cf_dataValidate output="qryErrors">

<cf_dataValidateItem type="required" value=“#form.FirstName#" message=“First Name is required">

</cf_dataValidate>

Parameters vary upon the TYPE of validation

TYPE and MESSAGE are required for all Types

Page 7: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

cf_dataValidateItem - Types Required Numeric SimpleValue LenLT LenGT Range Compare Email

Space Repex 3of4 Date DateCompare DateRange DateGT DateLT

Page 8: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

Displaying Errors Depends on the specified TYPE in the

parent tag cf_datavalidate 2 ways to display the error messages

1. Query – loop through the query of messages

2. Structure – Re-display the form and show the error message associated with each field (a little more advanced and requires some form manipulation)

Page 9: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

Displaying Errors - Query The error messages are placed in a query that you

can loop through<cf_dataValidate output=“qryErrors” type =“query”>

<cf_dataValidateItem type="required" value=“#form.FirstName#” message=“First Name is required">

</cf_dataValidate>

<cfif qryErrors.RecordCount>

<cfoutput query=“qryErrors”>

#qryErrors.message#<br>

</cfoutput>

<cfabort

</cfif>

Page 10: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

Displaying Errors - Structure Requires form manipulation Form needs to be included in the template

that does the validation The parameter FORMFIELD is required in

the child tag <cf_dataValidateItem><cf_dataValidate output=“qryErrors” type =“structure”>

<cf_dataValidateItem type="required" value=“#form.FirstName#” message=“First Name is required“ formfield=“FirstName”>

</cf_dataValidate>

Page 11: Derrick Rapley adrapley@rapleyzone.com Maryland CFUG October 8, 2002

Including Custom Validation Include the custom scenario inside

cf_datavalidate<cf_dataValidate output=“qryErrors” type =“query”>

<cf_dataValidateItem type="required" value=“#form.FirstName#” message=“First Name is required">

<cfif form.company NEQ “ACME Anvils”>

<cf_dataValidateItem type=“custom” message=“Custom Error”>

</cfif>

</cf_dataValidate>