Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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