>- see footer for list info -<
The best way is to use clientside and server side validation.

Clientside is better for the users that have javascript enabled, cause it
means a faster user experience.

Server side validation takes care of the users that have javascript
disabled.

Could be a bit overkill doing both, it depends how thourough you want to be.

hth
mark

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Stephen Adams
Sent: 24 November 2004 16:45
To: Coldfusion Development
Subject: RE: [CF-Dev] Best way to check if a form field is empty


>- see footer for list info -<
Yes it is, generally I am validating forms quiet a lot, and I'm just trying
to get an idea of the best method, which I can use every time I need to
validate a form.


 -----Original Message-----
From:   [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]  On Behalf Of Duncan Cumming
Sent:   24 November 2004 16:30
To:     [EMAIL PROTECTED]
Subject:        Re: [CF-Dev] Best way to check if a form field is empty

>- see footer for list info -<
two ways:
1. Javascript on the page with the form.  Either use <cfinput required="yes"
message="Please enter your name">, or roll your own. Problems - requires
Javascript to be enabled in the browser to work, so disabling javascript
gets around the validation.

2. Server-side with validation.  On the page you submit to, have something
like: <cfparam name="Form.fieldname1" default=""> <cfparam
name="Form.fieldname2" default="">

<cfif NOT Len(Trim(Form.fieldname1))>
  <cflocation url="page1.cfm?error=fieldname1">
</cfif>
<cfif NOT Len(Trim(Form.fieldname2))>
  <cflocation url="page1.cfm?error=fieldname2">
</cfif>


Then on the first page, have something like:

<cfparam name="URL.error" default="">
<cfif Len(URL.error)>
  <cfswitch expression="#URL.error#">
    <cfcase value="fieldname1">
      You must enter a value for fieldname 1
    </cfcase>
    <cfcase value="fieldname2">
      You must enter a value for fieldname 2
    </cfcase>
  </cfswitch>
</cfif>

Very basic, but gives you an idea of what to do.  Of course I'm assuming
this is why you want to know if the field is empty.

Duncan Cumming
New Media Developer
700 4105 / 01592 414105

>>> [EMAIL PROTECTED] 24/11/2004 16:12:10 >>>
>- see footer for list info -<


**********************************************************************
This email and any files transmitted with it are confidential and intended
solely for the use of the individual or entity to whom they are addressed
and should not be disclosed to any other party. If you have received this
email in error please notify your system manager and the sender of this
message.

This email message has been swept for the presence of computer viruses but
no guarantee is given that this e-mail message and any attachments are free
from viruses.

Fife Council
Tel: +44 (0) 1592 414141
**********************************************************************

_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help 
>-<

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System. For
more information please visit http://www.messagelabs.com/email
______________________________________________________________________

_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help 
>-<

_______________________________________________

For details on ALL mailing lists and for joining or leaving lists, go to 
http://list.cfdeveloper.co.uk/mailman/listinfo

--
CFDeveloper Sponsors:-
>- Hosting provided by www.cfmxhosting.co.uk -<
>- Forum provided by www.fusetalk.com -<
>- DHTML Menus provided by www.APYCOM.com -<
>- Lists hosted by www.Gradwell.com -<
>- CFdeveloper is run by Russ Michaels, feel free to volunteer your help -<

Reply via email to