Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 29th, 2004, 08:59 AM
Authorized User
 
Join Date: Jul 2004
Location: Chicago, , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Night_Zero
Default Making check boxes and emails

Below is the code that at the moment gets all the required info I need and displays it in three columns. Yay. Anyway, now I need to make a check box next to each email address(Multiple per company). If the check box is checked when they click a send button it'll email a file along with their new password to each email address for that company. Any help with making this section would be appreciated. Thanks. Below is the code thus far.

<%Option Explicit%>
<HTML>
<HEAD>
<TITLE>Testing</TITLE>
</HEAD>
<BODY>

<%
    dim cn, sql, rs
    Set cn = CreateObject("ADODB.Connection")

    cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
        "Data Source=c:\inetpub\database\ftp.mdb;" & _
        "Jet OLEDB:System Database=\\matrix\database\dent32\dent32.mdw" , _
        "Hidden", "hidden"

    set rs = server.createobject("adodb.recordset")
    sql = "SELECT PASSWORD.Password, PASSWORD.IsCurrent, PASSWORD.Assigned, PASSWORD.ID, CLIENT_CONTACTS.[CONTACT EMAIL], CLIENT.[CLIENT NAME] " & _
          "FROM [PASSWORD], CLIENT_CONTACTS, CLIENT " & _
              "WHERE (((PASSWORD.IsCurrent)=-1) AND ((PASSWORD.Assigned)=#4/16/2004#) AND ((PASSWORD.ID)=[CLIENT_CONTACTS].[CLIENT ID] And (PASSWORD.ID)=[CLIENT].[CLIENT ID]));"

    response.write("<h5>Check the check box if you would like to email the client his username and password</h5>")
    response.write("<b>[u]Client Name</u> [u]ID</u> [u]Contact Email</u> </b>") & "<br>" & "<br>"

    rs.Open sql, cn

    if not rs.eof then
        do while not rs.eof
        response.write rs("CLIENT NAME") & " " & _
                       rs("ID") & " " & _
                       rs("CONTACT EMAIL") & "<br>"
        rs.movenext
        loop
    end if
    rs.close
    set rs = nothing

%>
</BODY>
</HTML>

Reply With Quote
  #2 (permalink)  
Old July 29th, 2004, 09:18 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Mentiri, Muara, Brunei.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hello,

  while response.write, u generate a form

dim i 'assigning control names and find no of controls generated
i=1
strHTML=strHTML & "<form name='frm1' action='filename.asp' method='post'>"

while not rs.eof
  strHTML=strHTML & "<input type='checkbox' name='chk" & i & "' value='1'><input type='hidden' name='txtUN" & i & "' value='" & rs("username") & "'>" & rs("username") & ...
rs.movenext
i=i+1
wend
strHTML=strHTML & "<input type='hidden' name='txtCount' value='" & i-1 & "'></form>"

in the other page,

dim chkCompName,counter
for j=1 to request("txtCount")
 chkCompName="chk" & j
 if request(chkComp)="1" then
    ...'do u r coding
 end if
next


I think this what u need

Reply With Quote
  #3 (permalink)  
Old July 31st, 2004, 08:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

This can also be done in a simpler way. Let me modify rajanikrishna's code here. Anything in GREEN can be ignored and Blue is the modifed code.

Code:
dim i 'assigning control names and find no of controls generated
i=1
strHTML=strHTML & "<form name='frm1' action='filename.asp' method='post'>"

while not rs.eof
strHTML=strHTML & "<input type='checkbox' name='chk" & i & "' value='1'>"
strHTML=strHTML & "<input type='hidden' name='txtUN" & i & "' value='" 
strHTML=strHTML & rs("username") & "'>" & rs("username") & ...
    strHTML=strHTML & "<input type='checkbox' name='chkUserNames' value='" & rs("username") & "'>"    
    rs.movenext
    i=i+1
wend
strHTML=strHTML & "<input type='hidden' name='txtCount' value='" & i-1 & "'></form>"
strHTML=strHTML & "</form>"
in the other page,

Code:
dim chkCompName,counter
for j=1 to request("txtCount")
Dim arrUserNames
arrUserNames = Split(Request("chkUserNames"))
for j=0 to Ubound(arrUserNames)
chkCompName="chk" & j
 if request(chkComp)="1" then
    ...'do u r coding 
 end if
    Do your Mailing code here for every arrUserNames(j)
next
Just by naming all the Checkboxes with same name and onsubmit - just a request(thatName) would result in all the values that are checked (separated by comma). So you don't have to use multiple checkboxes and HIDDEN fields there, and thereby don't have to loop through to get its values. Instead you can split that into an array and loop through and add your mail processing code.

Hope that helps
Cheers!
_________________________
- Vijay G
Strive for Perfection
Reply With Quote
  #4 (permalink)  
Old August 1st, 2004, 08:20 PM
Friend of Wrox
 
Join Date: Sep 2003
Location: Mentiri, Muara, Brunei.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Yeah Vijay,

  You are right. We can do like that also.

Reply With Quote
  #5 (permalink)  
Old August 2nd, 2004, 12:07 AM
Authorized User
 
Join Date: Jul 2004
Location: Chicago, , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Night_Zero
Default

Appreciate the help but you're going to have to explain this. You say other page and all this, so uh...can you explain step by step whats going on? Also, will this mail each user their correct user name only if their name is checked? Also, I need to attach a document to each email. Thanks.

Reply With Quote
  #6 (permalink)  
Old August 2nd, 2004, 02:57 AM
Friend of Wrox
 
Join Date: Sep 2003
Location: Mentiri, Muara, Brunei.
Posts: 363
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

  When you generate the form dynamically, display it(with checkbox's). This is submitted to another page where u can send mail, attachments, and can identify which checkbox is checked and the other form data. When the checkbox is checked the checkbox value is submitted. Based on that value, u can identify which one is checked.

Vijay had already explained this.

To send mail : Use CDONTS/ASPMail objects
Ex: set objMail=server.createObject("CDONTS.NewMail")
objMail.to="to email"
objMail.subject="mail subject"
objMail.From="from mail"
objMail.attachFile ...

Note: Upload the file to be attached to the server first.
Use ASPSmartUpload control or other availble upload controls to upload file.



Reply With Quote
  #7 (permalink)  
Old August 2nd, 2004, 04:46 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by rajanikrishna
 Yeah Vijay,
You are right. We can do like that also.
Yes, it can be done in this way too. But in the solution that was suggested in your post, I don't find any need for hidden fields. That makes things complex by creating as many hidden fields as the nubmer of checkboxes required. An one would have to request those many fields from the server after form submission, looping through all those fields based on the hidden counter field, which I personally would say is a slower approach.

The one I suggested, would create an array of checkboxes and on request by its name it would all be returned as comma seperated string, which then can be split into array and all that would not take much of server resource, compared to the other.

So, one should always choose the much efficient and easier way.

Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
  #8 (permalink)  
Old August 2nd, 2004, 05:13 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Quote:
quote:Originally posted by Night_Zero
 Appreciate the help but you're going to have to explain this. You say other page and all this, so uh...can you explain step by step whats going on?
 All that in green are comments on the following line(s) of code.
Code:
This code declares a form tag, and action attribute defines 
the page to which this form gets submitted on click of SUBMIT button
strHTML=strHTML & "<form name='frm1' action='filename.asp' method='post'>"

Assuming that you would populate a recordset(rs) with all usernames/email addresses 
to which mails are to be sent, the following WHILE loop, loops through the recordset to display 
checkboxes for those users, each having its value as the EMAILADDRESS_UserName_Password
while not rs.eof
    strHTML=strHTML & "<input type='checkbox' name='chkEmails' value='" & rs("Email") & "_" rs(username) & "_" & rs(password) & "'>"    
    rs.movenext
wend
Form tag is closed here.
strHTML=strHTML & "</form>"
Displays the form with all generated check boxes.
Response.write strHTML
Here the Other page, can be the same page too, if your form action is pointing to the same page.
<form action="AnyPage.asp"....> which means this form values would be submitted to AnyPage.asp,
where you can code for request of the form values and process, as metioned below

Code:
Dim arrEmails
following line requests form field "chkEmails" from the server, 
splits that into an array, and stores it into "arrEmails"
arrEmails = Split(Request("chkEmails"))
Loop through the array, where each value would be an email 
address to which you got to send an email.
for j=0 to Ubound(arrEmails)
    As the example given in RajaniKrishna's previous post, emailing code should come here. 
ObjCDONTSNewMail.TO should hold the value in current subscript of the array.
    arrTemp=split(arrEmails(j),"_")
    strEmail=arrTemp(0)
    strUserName=arrTemp(1)
    strPassword=arrTemp(2)
    objMail.to=strEmail
    'Do your Mailing code here for every strEmail.
    Use strUserName and strPassword as content to that mail body.
next
Quote:
quote:Also, will this mail each user their correct user name only if their name is checked? Also, I need to attach a document to each email.
The above code would mail each user their correct username and password only if their name is checked,
provided your SELECT statement is CORRECT. Check for attachFile property of CDONTs MAIL object for attaching file.

I think I haven't explained anyone so elaborate as this.
(You may better give me access to your system, I would finish this off for you.;))

Hope this explains well, all that you needed.
Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
  #9 (permalink)  
Old August 2nd, 2004, 11:32 AM
Authorized User
 
Join Date: Jul 2004
Location: Chicago, , .
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Night_Zero
Default

Alright, I read your descriptions and explananations and I appreciate it but two things. I have my asp code at the moment in test.asp. In this all it does is get the info and then display it to the screen. The code is in the above posts. Do I still need to use this or can I just take the select statement? Also, when you go to the page which should I guess be an asp page it should list all the names and check boxs. Then when you hit submit it should mail everyone who's name is checked. This possible?

Reply With Quote
  #10 (permalink)  
Old August 3rd, 2004, 05:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

I am not sure, what you are trying to do in test.asp, if that is just to test out this functionality, you can modify the same page with the suggested code here.

Just after the rs.Open line, you can add the form code and get that submitted to same page or another page, whichever you feel comfortable with, and display appropriate messages so that you test out the entire flow.

Feel free to post here for clarifications.
Cheers!

_________________________
- Vijay G
Strive for Perfection
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop over check boxes sams ASP.NET 1.0 and 1.1 Professional 5 July 17th, 2007 06:26 AM
Check Boxes Allan320 Access VBA 3 June 2nd, 2006 05:45 AM
Using check boxes to filter dstein4d Access VBA 13 January 25th, 2006 07:50 PM
Disable Check Boxes sweet4511 VB How-To 22 July 19th, 2005 03:53 PM
Getting value of Dynamic Check boxes kathryne Classic ASP Databases 3 March 19th, 2004 05:44 AM



All times are GMT -4. The time now is 02:05 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.