Skip to main content
Known Participant
October 10, 2009
Question

Submit a blank field

  • October 10, 2009
  • 2 replies
  • 1363 views

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>

    This topic has been closed for replies.

    2 replies

    Inspiring
    October 11, 2009

    Use this

    <cfif len (Form.EmailAddress) is 0 >

    .

    .

    </cfif

    Participating Frequently
    October 11, 2009

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

    Inspiring
    October 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

    straffenpAuthor
    Known Participant
    October 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?

    Inspiring
    October 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