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

How to check for blank fields ?

Participant ,
Jun 28, 2009 Jun 28, 2009

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.

719
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
Contributor ,
Jun 28, 2009 Jun 28, 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

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
Participant ,
Jun 29, 2009 Jun 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 > ??

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
Advisor ,
Jun 29, 2009 Jun 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) />

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
Contributor ,
Jun 29, 2009 Jun 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))>

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

</cfif>

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

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

</cfif>

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

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

</cfif>

etc...

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
Valorous Hero ,
Jun 29, 2009 Jun 29, 2009
LATEST

The suggestion by JR "Bob" Dobbs is more elegant.  You could also use list functions and skip the arrayToList step .But that is a mainly matter of personal preference.

Also, do not forget about non-blank values that are _not_ a valid emails.  You may wish to skip them, as in  JR "Bob" Dobbs' example, or do something else.

emailaddr_1 = (blank)

emailaddr_2 = "foobar"   <<---- this is invalid.

emailaddr_3 = "me@somewhere.com"

...

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