Skip to main content
Inspiring
June 29, 2009
Question

How to check for blank fields ?

  • June 29, 2009
  • 1 reply
  • 847 views

I have a form that contains six input fields used for email addresses.

Once all six are filled out, I can create a concatenated string with the six input fields, separated by a comma, to be used in the cfmail to part.

What if they do not fill out all six input fields and only fillout two of the input fields with email addresses. ?

What is an efficient way to check if a field was filled out or not, with an email address ? My concatenated string will then only contain 2 input fields.

    This topic has been closed for replies.

    1 reply

    Dileep_NR
    Inspiring
    June 29, 2009

    Hi,

    try this,

    <cfset concatenated="">

    <cfif len(trim(form.fieldname))>

    <cfset concatenated =  concatenated  & form.fieldname & ",">

    </cfif>

    for validating email

    IsValid("email",(trim(form.fieldname)))

    also ref :

    http://livedocs.adobe.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=ColdFusion_Documentation&file=00000534.htm

    trojnfnAuthor
    Inspiring
    June 29, 2009

    Thanks for the reply.

    So if I have six input fields, they would have different names, fieldname_1, fieldname_2, etc.

    So your code would be :

    <cfset concatenated="">

    <cfif len(trim(form.fieldname_1))>

    <cfif len(trm(form.fieldlname_2)>

    etc...

    <cfset concatenated = concatenated & form.fieldname1 & "," & form.fieldname2 & "," ....etc > ??

    Inspiring
    June 29, 2009

    Here is a sample.  Note I have not tested this code.  Assumes that the text fields are consistently named as 'emailaddr_1' to 'emailaddr_6' and all are supplied on the post action of your form.

    <cfset emailAddresses=ArrayNew(1) /> <!--- initialize array --->

    <!--- loop the number of email form fields on your form --->
    <cfloop from="1" to="6" index="idx">
        <cfif IsValid("email", form["emailaddr_#idx#"])> <!--- ignore any values that are not email addresses, use array notation to get email_x value  --->
            <cfset ArrayAppend(emailAddresses,  form["emailaddr_#idx#"]) />
        </cfif>
    </cfloop>

    <!--- convert array to comma delimited list --->
    <cfset emailList=ArrayToList(emailAddresses) />