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

Sending out 2 separate Email Responders? cfform

Explorer ,
Jul 02, 2008 Jul 02, 2008
Hello,
I've been using coldfusion here at work lately to generate leads for our customers. I ran into a road block when I was asked to create a cfform that asked 5 questions and based off of the questions you've picked you would get a different email send to you.

Example Question:
Do you or anyone in your household have a monthly income of $1500 or higher?
Check Box - Yes | No

What I am looking for is if the user clicks the Yes check box and submits his form he will get an email that says his application has been accepted.

But if the user clicks the No check box and submits his form he will get an email that say his application will not be accepted.

What's the easiest and most efficient way to make this happen with Coldfusion?
TOPICS
Getting started
1.1K
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 ,
Jul 02, 2008 Jul 02, 2008
Something more complex then just a basic programming branch AKA an if
statement?

Pseudo Code:
if [some condition] then
do this code
else
do that code


In ColdFusion that would often look like this:
<cfif form.aField EQ "Yes">
<cfmail...>
You are accepted
</cfmail>
<cfelse>
<cfmail...>
You are rejected
</cfmail>
</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
Explorer ,
Jul 02, 2008 Jul 02, 2008
Thank Ian Skinner for your reply.
How would I specify all of the questions in the cfif statement though?

The problem I have is I just don't understand where to start at in order to make the cfif statement work with the 5 questions.

here is the form
http://mswebsol.com/gaslockguarantee/creditapplication.cfm

I'm just confused I assume.
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 ,
Jul 02, 2008 Jul 02, 2008
quote:

Originally posted by: xstortionist
Thank Ian Skinner for your reply.
How would I specify all of the questions in the cfif statement though?

The problem I have is I just don't understand where to start at in order to make the cfif statement work with the 5 questions.

Start by writing down in plain english what your permutations and combinations are. Once you have that done, convert it to cfml.
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 ,
Jul 02, 2008 Jul 02, 2008
xstortionist wrote:
> Thank Ian Skinner for your reply.
> How would I specify all of the questions in the cfif statement though?
>

How - you would use the appropriate combination of AND, OR, NOT and
other boolean operators.

How to use these operators depends on exactly what results you want.
This topic is 'Boolean' logic and entire chapters, books, college
courses are dedicated to this topic.


The basic format would be

if [condition A] AND [condition B] OR [condition C] 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
Advocate ,
Jul 02, 2008 Jul 02, 2008
Taking a look at your form, I'd like to suggest a few things to alter in the front-end form itself to make your life easier on the back-end.

1. You are using checkboxes for yes and no. Change these to radio buttons, where only one can be selected (I am assuming you don't want someone selecting yes AND no on the same question).
The input tag would look like the following
<input type="radio" name="q1" id="q1" value="yes" />
<input type="radio" name="q1" id="q1" value="no" />
2. Currently you have each input element for the checkboxes with a unique name. This makes your server-side validation more difficult than necessary. Notice above how both the name and id of the question 1 radio elements are the same (q1). This groups the two radio buttons together and makes server-side validation (IMO).

One the server side, you could do something along the lines of the following (NOT optimal code...just meant to get you rolling:
<cfif StructKeyExists(form,"q1")>
<cfif form.q1 is "yes">
<cfmail>accepted....</cfmail>
<cfelse>
<cfmail>not accepted...</cfmail>
</cfif>
<cfelseif StructKeyExists(form,"q2")>
<cfif form.q2 eq "yes">
<cfmail>accepted....</cfmail>
<cfelse>
<cfmail>not accepted...</cfmail>
</cfif>
<cfelseif ....>
<cfif form.q1 eq "yes">
<cfmail>accepted....</cfmail>
<cfelse>
<cfmail>not accepted...</cfmail>
</cfif>
</cfif>

This pseudo-code is using the native ColdFusion function/method StructKeyExists to check if the form field was passed in (CF passes all form data to the processing page as a struct/structure). This is a fast way to check if a field, such as a radio button, was sent from the form.

So, in our example, if the form field q1 exists in the form structure, someone selected yes or no for that question. Then, you can use an added conditional (cfif) statement to check the value of the selected radio button. In this case, it's a string for yes or no. If it's yes, send one email. If no, send the other.

Again, none of that is optimized...just my quick reply. Also, none of this replaces what Ian and Dan mention (learn more about booleans and it's always great to write out your steps in plain English and then worry about turning it into working code).

Hope this helps!
Craig
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 ,
Jul 02, 2008 Jul 02, 2008
Craig thank you for the reply.

I'm very happy that you mentioned radio buttons because I was right in the middle of switching the checkboxes to radio buttons as I received the email response from you.

I like your method and I'm going to give it a try. I broke out my CFMX7 Web Application Construction Kit book and was reading through a few form chapters that mentioned radio and check boxes. I will update you with my progress so you can all see how this works out for me.

thank you for being very kind and giving me great tips. I will keep being open minded and try to get better with coldfusion.

I'll write back in a few hours when I get the script finished.
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 ,
Jul 02, 2008 Jul 02, 2008
craig

I have a quick question for you. you wrote out the code "<cfif StructKeyExists(form,"q1")>" My question is where it says "(form, "q1")" Do I need to specify the name of the form? Or does it already recognize that it's the form that's being processed? Does this make sense?

thanks you've been a big help.
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 ,
Jul 02, 2008 Jul 02, 2008
I found out the solution.

Apparently Firefox makes a decision to select the first Radio button if there is a <label> tag around the buttons.

I deleted the <label> tag and now I can select the different buttons.

Note: This worked in IE6 Fine with the <label> tag. Firefox it doesn't work.
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
Advocate ,
Jul 02, 2008 Jul 02, 2008
Glad to help and I hope it works out for you :)! Keep us posted...CF is a fantastic language and I can all but guarantee that as you get into it, you'll love it more and more! As a language/server, it just keeps getting better.

Cheers,
Craig
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 ,
Jul 02, 2008 Jul 02, 2008
You don't have to specify the name of the form. For what it's worth, <cfdump var="#form#"> is one of my favourite troubleshooting lines of code.
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
Advocate ,
Jul 02, 2008 Jul 02, 2008
It does make sense and, no, you do not need to specify the name of the form. When CF submits a form, it takes all elements and adds them to the form structure. So, (form, "q1") will look for the structure names form and then a key in that structure called q1.

As a helpful tool, add the following to the top of the CFML page that processes your form:
<cfdump var="#form" />
<cfabort/>

This will dump out the entire form structure and show you what's inside it (the cfabort tag stops all other processing in its tracks). It can be pretty helpful to see what is coming over. Try it with various fields selected or not selected in your form (this way you can see all the different data that's passed in).

Cheers,
Craig
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 ,
Jul 02, 2008 Jul 02, 2008
Awsome! Thanks Craig and Dan. This is very useful for me.

I've ran into a problem with the radio buttons. Right now I am only able to select the Yes Radio button on my form. You can check it out at the link below:
http://mswebsol.com/gaslockguarantee/creditapplication.cfm

here is a sample code of one of the lines with the radio buttons.

<label>Yes
<cfinput type="radio" name="Q1" id="Q1" value="yes" />
No
<cfinput type="radio" name="Q1" id="Q1" value="no" />
</label>

any idea why this is happening?
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 ,
Jul 02, 2008 Jul 02, 2008
Craig
Just letting you know that the script is now working. I wanted to thank you and dan for all the help that you've given me.

I've yet to see an email be sent to me as a test yet due to our mail server having issues. I'm sure I'll be back with some more questions.

Just wanted to thank you all.

Also the CFDump was a great help with my form processing. I am going to be using it for now on.
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 ,
Jul 02, 2008 Jul 02, 2008
LATEST
each of the radio buttons in a group should have a separate label:

<label>Yes <cfinput type="radio" name="Q1" id="Q1" value="yes" /></label>
<label>No <cfinput type="radio" name="Q1" id="Q1" value="no" /></label>


Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.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
Advocate ,
Jul 02, 2008 Jul 02, 2008
Sorry, Dan! Didn't mean to duplicate the response. I submitted my reply as yours was coming in :)!
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 ,
Jul 02, 2008 Jul 02, 2008
craigkaminsky wrote:
> When CF submits a form, it takes all elements and adds them to the form
> structure. ...

To nitpick CF does not submit a form, it receives a form from the web
server. This point is not necessary to grasp to understand how to use
the form structure that is being discussed.

But it is often a source of confusion in beginning ColdFusion
developers. It is very helpful to understand the roles each layer plays
and not confusing which does what. The web application, the client, the
web server and the application server (or favorite being ColdFusion
naturally) all have different responsibilities and a lot of grief can be
avoided when this is understood.

O.K. I'll get back to eating my lunch and get off this soapbox.


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