[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 193
  • Last Modified:

Displaying name and email address based on checkbox

hey guys,

see http://www.experts-exchange.com/Web/WebDevSoftware/ColdFusion/Q_21782992.html regarding my question similar to this one but this one has a twist.

I have an admin area where coaches can view their roster and select checkboxes to send emails to certain players. That part works great thanks to mkishline. The SendEmailList.cfm page lists the roster with a checkbox per player that allows me to send emails to 1 or all of the players. That info gets sent to a SendEmailCompose.cfm page which has a form the coach can fill out.....email subject, email body. I also have listed on that page the email address to which that email will be sent based on the checkboxes on the previous page. This is done with cfloop. I would like to be able to show the email address as well as the players name on that SendEmailCompose.cfm page. I cant seem to get that part right. I have posted my code for those 2 pages below. Thanks for your help

IShiva

SendEmailList.cfm

<cfquery name="PlayerView" datasource="datasource">
SELECT *
FROM #SESSION.Auth.tblPlayers#
ORDER BY PlayerGrade DESC, PlayerLastName
</cfquery>

<tr>
<cfinclude template="NavBar.cfm">
<td width="630" valign="top" bgcolor="#ffffff">
<table width="630" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#fff8dc"><img src="images/corner.gif">Send informational team emails to your <cfoutput>#SESSION.Auth.Gender#</cfoutput> players.</td>
</tr>
<tr>
<td height="5" bgcolor="#fff8dc"></td>
</tr>
<tr>
<td class="frame">
<table cellpadding="3" cellspacing="0" width="100%">
<tr>
<td>
<table cellpadding="5" cellspacing="0" width="100%">
<tr bgcolor="#d5d6c6">
<td class="text6"><strong>Last Name</strong></td>
<td class="text6"><strong>First Name</strong></td>
<td class="text6"><strong>Grade</strong></td>
<td class="text6"><strong>Level</strong></td>
<td class="text6"><strong>Email</strong></td>
<td class="text6"><strong>Send Email</strong></td>
</tr>
<cfform action="SendEmailCompose.cfm" name="SendEmailForm">
<cfoutput query="PlayerView">
<tr bgcolor="###iif(currentrow MOD 2,DE('ffffff'),DE('f1f2ed'))#">
<td class="frameBottom">#PlayerView.PlayerLastName#</td>
<td class="frameBottom">#PlayerView.PlayerFirstName#</td>
<td class="frameBottom">#PlayerView.PlayerGrade#</td>
<td class="frameBottom">#PlayerView.PlayerLevel#</td>
<td class="frameBottom">#PlayerView.Playeremail#</td>
<td class="frameBottom"><cfinput type="checkbox" name="PlayerEmail" value="#PlayerView.PlayerEmail#" checked="no"></td>
</tr>
</cfoutput>
<tr>
<td colspan="6" align="right"><input type="submit" name="submit" value="Send Emails"></td>
</tr>
</cfform>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>


SendEmailCompose.cfm

<tr>
<cfinclude template="NavBar.cfm">
<td width="630" valign="top" bgcolor="#ffffff">
<table width="630" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#fff8dc"><img src="images/corner.gif">Create your email.</td>
</tr>
<tr>
<td height="5" bgcolor="#fff8dc"></td>
</tr>
<tr>
<td class="frame">
<table cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top">
<cfform action="SendEmailAction.cfm" name="SendEmailForm">
<input type="hidden" name="PlayerEmail" value="<cfoutput>#form.PlayerEmail#</cfoutput>">
<table cellpadding="5" cellspacing="0" width="100%">
<tr>
<td><strong>Subject:</strong><br><cfinput type="text" name="subject" required="yes" message="Enter a subject." size="50"></td>
</tr>
<tr>
<td><strong>Enter Newsletter:</strong><br><textarea name="Description" cols="75" rows="15"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Send Email"></td>
</tr>
</table>
</cfform>
</td>
<cfset list = "#form.PlayerEmail#">
<td valign="top">
<table cellpadding="2" cellspacing="0">
<tr>
<td><strong>Email recipients:</strong></td>
</tr>
<cfloop list="#list#" index="i">
<tr>
<td><font size="-2"><cfoutput>#i#</cfoutput></font></td>
</tr>
</cfloop>
</table>
</td>
</tr>
</table>
</td>

</tr>
</table>
</td>
</tr>


0
IShiva
Asked:
IShiva
  • 8
  • 5
1 Solution
 
mkishlineCommented:
On SendMailCompose.cfm:

<cfquery name="PlayerInfo" datasource="datasource">
SELECT *
FROM #SESSION.Auth.tblPlayers#
WHERE playerEmail IN (<cfqueryparam value="#form.PlayerEmail#" />)
ORDER BY PlayerGrade DESC, PlayerLastName
</cfquery>

and then you can change:
<cfset list = "#form.PlayerEmail#">
<td valign="top">
<table cellpadding="2" cellspacing="0">
<tr>
<td><strong>Email recipients:</strong></td>
</tr>
<cfloop list="#list#" index="i">
<tr>
<td><font size="-2"><cfoutput>#i#</cfoutput></font></td>
</tr>
</cfloop>
</table>

to
<table cellpadding="2" cellspacing="0">
  <tr><td><strong>Email recipients:</strong></td></tr>
  <cfoutput query="playerInfo">
    <tr><td>#firstname# #lastname#: #playerEmail#</td></tr>
  </cfoutput>
</table>
0
 
IShivaAuthor Commented:
I changed the code like you said, and it works if i only choose 1 checkbox...When I choose multiple players, there is no error, but nothing is displayed under the 'Email Recipients'...it is blank.

Any suggestions?  Here is my code.

<link href="scripts/style.css" rel="stylesheet" type="text/css">


<tr>
<cfinclude template="NavBar.cfm">
<td width="630" valign="top" bgcolor="#ffffff">
<table width="630" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#fff8dc"><img src="images/corner.gif">Create your email.</td>
</tr>
<tr>
<td height="5" bgcolor="#fff8dc"></td>
</tr>
<tr>
<td class="frame">
<table cellpadding="3" cellspacing="0" width="100%">
<tr>
<td valign="top">
<cfform action="SendEmailAction.cfm" name="SendEmailForm">
<input type="hidden" name="PlayerEmail" value="<cfoutput>#form.PlayerEmail#</cfoutput>">
<table cellpadding="5" cellspacing="0" width="100%">
<tr>
<td><strong>Subject:</strong><br><cfinput type="text" name="subject" required="yes" message="Enter a subject." size="50"></td>
</tr>
<tr>
<td><strong>Enter Newsletter:</strong><br><textarea name="Description" cols="75" rows="15"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Send Email"></td>
</tr>
</table>
</cfform>
</td>
<cfquery name="PlayerInfo" datasource="mydsn">
SELECT *
FROM #SESSION.Auth.tblPlayers#
WHERE playerEmail IN (<cfqueryparam value="#form.PlayerEmail#" />)
ORDER BY PlayerGrade DESC, PlayerLastName
</cfquery>
<td valign="top">
<table cellpadding="2" cellspacing="0">
<tr>
<td><strong>Email recipients:</strong></td>
</tr>
<cfoutput query="playerInfo">
<tr>
<td><font size="-2">#PlayerFirstName# #PlayerLastName#<br>
&nbsp;&nbsp;&nbsp;&nbsp;#PlayerEmail#</font></td>
</tr>
</cfoutput>
</table>
</td>
</tr>
</table>
</td>

</tr>
</table>
</td>
</tr>
0
 
IShivaAuthor Commented:
forgot this .......the emails are still sent correctly and to multiple players if I select them.....that part works great....it just wont output the recipients if the are greater than 1.
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
mkishlineCommented:
In one of the <td> tags after the PlayerInfo query, add a <cfdump var="#PlayerInfo#" /> and see what the query is returning. Also double check the source on SendMailCompose.cfm and make sure you're getting a comma-delimited list of email addresses.
0
 
IShivaAuthor Commented:
yes, in the source, all the emails are they seperated by commas..

Im confused as to where the cfdump code should go...can you specify?
0
 
IShivaAuthor Commented:
got it...

cfdump shows up when only 1 player is checked.....not multiple

Source from SendMailCompose.cfm

<FORM NAME="SendEmailForm" ACTION="SendEmailAction.cfm" METHOD="POST" onSubmit="return _CF_checkSendEmailForm(this)">
<input type="hidden" name="PlayerEmail" value="user@yahoo.com,user@hotmail.com,user@aol.com">
<table cellpadding="5" cellspacing="0" width="100%">

<tr>
<td><strong>Subject:</strong><br><INPUT TYPE="text" NAME="subject" SIZE="50"></td>
</tr>
<tr>
<td><strong>Enter Newsletter:</strong><br><textarea name="Description" cols="75" rows="15"></textarea></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Send Email"></td>
</tr>
</table>
</FORM>
</td>
                                          
<td valign="top">
<table cellpadding="2" cellspacing="0">
<tr>
<td><strong>Email recipients:</strong></td>
</tr>
</table>
</td>
0
 
mkishlineCommented:
If you put:

<td><strong>Email recipients:</strong><cfdump var="#PlayerInfo#" /></td>

does it return a record for each player whose email you selected on the previous page?
0
 
IShivaAuthor Commented:
no, it returns nothing when multiple players are checked. it does return the correct info when only 1 player is checked however.

I put the <cfdump> inside the <cfoutput query="PlayerInfo"> as well as outside....and still only returns information when only 1 player is checked
0
 
mkishlineCommented:
Try changing the PlayerInfo query to this (leave in the cfdumps) and let me know if that returns the proper number of records:

<cfquery name="PlayerInfo" datasource="dbname">
      SELECT *
      FROM #SESSION.Auth.tblPlayers#
      WHERE playerEmail = <cfqueryparam value="#ListFirst(form.PlayerEmail)#" CFSQLType="CF_SQL_VARCHAR" />
      <cfloop index="i" list="#ListRest(form.PlayerEmail)#">
      OR playerEmail = <cfqueryparam value="#i#" CFSQLType="CF_SQL_VARCHAR" />
      </cfloop>
      ORDER BY PlayerGrade DESC, PlayerLastName
</cfquery>
0
 
IShivaAuthor Commented:
YES!!!

That worked!! What a query...way over my head!

I should be good to go now? Or is there anything else I need to do?
0
 
IShivaAuthor Commented:
Ive noticed that sometimes either cfmail OR my domain 'freeze' up. (Im not sure what to call it). Sometimes after I click the 'send email now' button, it goes to SendEmailAction.cfm and thento my thank you page since I have <cflocation> pointing to home.cfm. Will the cflocation only execute if the code above executed correctly? Im thinking that sometimes after I click the send email now button....lets say i checked 5 players.....it gives me the thank you page but I dont know if its complete....

because sometimes when i test it again, after i click the send email now button, it hangs....and i have to restart CF server and the ODBC agent and server in the Administrative Tools in XP....it then resets itself and i am able to send again correctly..

i believe the problem is that the access DB locks (i notice .ldb in the database directory when I check it)...that only goes away if i reset everything.

is there code that i can place on the action page so that it doesnt go to the thank you page until everything is sent and completed correctly?

Why would it hang like that? I am testing it locally on my machine not on a web host.

Is there anything i can do to prevent the hanging and the resetting of CF server?
0
 
mkishlineCommented:
The cfmail tag doesn't return or create any information that you'll be able to use to determine if the mail was sent successfully. If the code is getting to the <cflocation> at the end of your file, all that tells you is there are no coldfusion syntax or processing errors. You can try:

<cftry>
  <cfmail to="...
  </cfmail>
  <cfcatch type="any">
   <cfdump var="#cfcatch#" />
   <cfabort />
  </cfcatch>
</cftry>

But that likely won't tell you any more information than you already know. Most likely you'll need to look through the mail logs on your server to check if the emails are going through.
0
 
IShivaAuthor Commented:
Thanks again for your help! Im sure I'll post something else today!! haha

IShiva
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 8
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now