{"id":482,"date":"2014-02-07T09:20:04","date_gmt":"2014-02-07T14:20:04","guid":{"rendered":"http:\/\/www.cfchimp.com\/wordpress\/?p=482"},"modified":"2024-12-05T20:10:04","modified_gmt":"2024-12-06T01:10:04","slug":"using-a-coldfusion-ternary-operator-for-an-optional-tag-attribute","status":"publish","type":"post","link":"https:\/\/csimmons.dev\/blog\/2014\/02\/using-a-coldfusion-ternary-operator-for-an-optional-tag-attribute\/","title":{"rendered":"Using a ColdFusion Ternary Operator for an Optional Tag Attribute"},"content":{"rendered":"<p>Today I had to write a script to process a form and send an email as part of the processing.  The form allows the user to specify an email address to bcc, but it&#8217;s not required.  I&#8217;m a big fan of using the Ternary Operator for doing either\/or stuff like css classes.  So I decided to extend that fandom to set the bcc attribute of the &lt;cfmail&gt; tag if the email specified in the form was valid.<\/p>\n<p>Assumptions for this example:<\/p>\n<p>1. You have validated form.bccEmail as a valid email.<br \/>\n2. You have a default mail server specified in Application.cfc or CFADMIN.<br \/>\n3. You may see more utility in using the Ternary Operator for other conditional cases.<\/p>\n<p>The &#8220;magic&#8221; is in the bcc attribute below:<\/p>\n<pre class=\"prettyprint\">\r\n    <cfmail to=\"someone@example.com\" \r\n        bcc=\"#Len(form.bccEmail)?form.bccEmail:''#\" \r\n        replyto=\"donotreply@example.com\" \r\n        failto=\"donotreply@example.com\" \r\n        from=\"donotreply@example.com\" \r\n        subject=\"An important message\" \r\n        type=\"html\">\r\n\t    Message Body here...\r\n    <\/cfmail>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Today I had to write a script to process a form and send an email as part of the processing. The form allows the user to specify an email address to bcc, but it&#8217;s not required. I&#8217;m a big fan of using the Ternary Operator for doing either\/or stuff like css classes. So I decided &#8230; <a title=\"Using a ColdFusion Ternary Operator for an Optional Tag Attribute\" class=\"read-more\" href=\"https:\/\/csimmons.dev\/blog\/2014\/02\/using-a-coldfusion-ternary-operator-for-an-optional-tag-attribute\/\" aria-label=\"Read more about Using a ColdFusion Ternary Operator for an Optional Tag Attribute\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_cloudinary_featured_overwrite":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[68],"tags":[48,12],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-developer","tag-coldfusion","tag-developer"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pbVg43-7M","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/comments?post=482"}],"version-history":[{"count":0,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"wp:attachment":[{"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/csimmons.dev\/blog\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}