Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CFForm Either / Or required

New Here ,
Apr 16, 2009 Apr 16, 2009

Hi,

I have a simple cfform with certain required fields. I would like to be able to make either of two fields required, either the email address field or the fax number field. I only need one or the other to be completed and tested for on submit.

Any ideas on how I could achieve this?

Cheers
Peter

1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Apr 16, 2009 Apr 16, 2009
LATEST

Hi Peter,

Two options:

1).  Use a javascript function that basically checks to see whether either of the two fields is something other than "".  Look for javascript code to activate based on the "onclick" of the submit button.  (Nice in that it doesn't go and hit the cf server)  ..sorry, my javascript is not up to par.

or

2).  Write a coldfusion code that checks to see if your visitor has filled in one or the other.  Use this code on the page you're submitting to:

<cfparam name="FORM.Email" default="">
<cfparam name="FORM.FaxNumber" default="">

<cfif listlen(FORM.Email) GTE 1 OR listlen(FORM.FaxNumber) GTE 1>

do something

<cfelse>

     <cflocation url="originalformpage.cfm">

</cfif>

cfwild

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources