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

Submit a blank field

New Here ,
Oct 10, 2009 Oct 10, 2009

Hi everyone,

I'm trying to use a cfif statement to check to see if users leave the email field in my form blank. See the code below. For some reason, if the user does enter an email address, the code works fine. If the field is left blank though, it seems that CF doesn't create the cfset with only the first and last names. Any suggestions? Is there a better way to check for an empty field?

Thanks!

<cfif '#Form.EmailAddress#' eq ''>
<cfset EmailFrom = '#Form.FirstName# #Form.LastName#'><cfelse>
<cfset EmailFrom = '#Form.FirstName# #Form.LastName#<#Form.EmailAddress#>'></cfif>

1.3K
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
LEGEND ,
Oct 10, 2009 Oct 10, 2009

Do a dump of the form struct before your logic here to make sure your form fields hold what you think they hold.

NB: you don't need - nor should have - quotes and pounds around your form field name in your <cfif> statement.

--

Adam

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
New Here ,
Oct 10, 2009 Oct 10, 2009

Thanks for the quick reply, Adam. I'm a novice, could you tell me how to do a dump of the form structure?

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
LEGEND ,
Oct 10, 2009 Oct 10, 2009

OK.  The first best tool for a novice is Google.  Google "coldfusion dump form struct", and there'll probably be some help there (I'll point you in the right direction, but it's good to get "google it" into one's head as the first port of call for any issue).

OK, so dumping stuff:

http://livedocs.adobe.com/coldfusion/8/htmldocs/Tags_d-e_08.html#3980281

CF scopes:

http://livedocs.adobe.com/coldfusion/8/htmldocs/Elements_08.html

And specifically forms:

http://livedocs.adobe.com/coldfusion/8/htmldocs/formatData_01.html

Also, if a novice, having a flick through the tag & function references @ livedocs is essential.  Don't try to remember everything, but you'll remember some stuff, and it'll give you a feel for what CF can do.

http://livedocs.adobe.com/coldfusion/8/htmldocs/Part_3_CFML_Ref_1.html

Sing out if you need more help.

--

Adam

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
Explorer ,
Oct 11, 2009 Oct 11, 2009

Use this

<cfif len (Form.EmailAddress) is 0 >

.

.

</cfif

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
New Here ,
Oct 11, 2009 Oct 11, 2009
LATEST

If you use the CFform construct there is an option called "required". Set it to yes.

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