[thelist] coding required form fields to work with Javascript turned off

matthew garrett matthew.garrett at snet.net
Sat Feb 23 07:36:01 CST 2002


> From: "Sharon F. Malone" <sfmalo at 24caratdesign.com>
> Veronica -
> How would I go about doing this?
CF has some automatic validation stuff, but here;'s an approximation of how
to do it yourself.

First:
Make your form a re-usable include which is used for adding AND editing the
info. Set default values to "", then output the values in the form. If the
form

Example
<cfparam name="field1data" default="">
<cfparam name="field2data" default="">
<cfoutput>
<form>
    <!--- this part is triggered by stuff on
        the processing page (see below) --->
    <cfif isdefined('missed_list')>
        <cfif findnocase(missedlist, 'field1')>
            Hey you forgot this field
        </cfif>
    <input type="text" name="field1" value="#field1data#">
    <input type="text" name="field2" value="#field2data#">
</form>
</cfoutput>

In the processing page test the form variables and re-include the form if
some are missing/incomplete:

<cfset requiredfields="field1, field2, field3">
<cfset missed_list="">
<cfloop list="requiredfields" index="current_field">
    <cfif current_field IS ''>
        <cfset missed_list=listappend(missed_list, current_field)>
    </cfif>
</cfloop>
<cfinclude template="form.cfm">

ok, i'm late for a meeting.... hope that points you in the right direction
matt




More information about the thelist mailing list