Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Form Processing

  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Lake Forest, CA
    Posts
    259
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Processing

    Is it possible to send a form to an email & to a database?

    I want a copy emailed to myself, and then also added to a database so I can access it from anywhere.

    Thanks
    The Wizzard
    OC Motor Cars | OC Auto Sports (Coming Soon!)

  • #2
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well, yes. Provided that you have access to an email component.
    Essentially it would go like this.
    Code:
    Set conn = server.createobject("Adodb.connection")
    Set rs = server.createobject("Adodb.recordset")
    conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ="&server.MapPath("db/yourDatabase.mdb")&";"
    
    sqlInsert = "INSERT INTO TableName (Field1,Field2,Field3) VALUES ('"&Request.Form("Field1")&"','"&Request.Form("Field2")&"','"&Request.Form("Field3")&"')"
    rs.Open sqlInsert, conn
    
    Set cdonts = Server.CreateObject("Cdonts.NewMail")
    cdonts.subject = "Form mail"
    cdonts.from = "youraddress@here.com"
    Body = "This and that"
    Body = Body & Request.Form("Field1") & " and " & Request.Form("Field2") & " and " & Request.Form("Field3")
    cdonts.body = Body
    cdonts.send
    set cdonts = Nothing
    Omnis mico antequam dominus Spookster!

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Except you'd also want to close the recordset - and also protect the insert statements from single quotes. It doesn't matter in the email, though.

    Code:
    Function SQLFormat(byVal str)
       If IsNull(str) Then str = ""
       SQLFormat = Replace(str,"'","''")   
    End Function
    
    Set Conn = Server.CreateObject("ADODB.Connection")
    Set rs = Server.CreateObject("ADODB.RecordSet")
    Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("db/yourDatabase.mdb") & ";"
    
    sqlInsert = "INSERT INTO TableName (Field1,Field2,Field3) VALUES ('" & SQLFormat(Request.Form("Field1")) & "','" & SQLFormat(Request.Form("Field2")) & "','" & SQLFormat(Request.Form("Field3")) & "')"
    rs.Open sqlInsert, Conn
    
    Set objMail = Server.CreateObject("CDONTS.NewMail")
    objMail.Subject = "Form mail"
    objMail.From = "youraddress@here.com"
    Message = "This and that"
    Message = Message & Request.Form("Field1") & " and " & Request.Form("Field2") & " and " & Request.Form("Field3")
    objMail.Body = Message
    objMail.Send
    set objMail = Nothing
    
    Set rs = Nothing
    Set Conn = Nothing
    P.S. I love lower-case variables in JavaScript, and camel-cased functions - but it annoys me to see stuff in VBScript typed all lower case (or in this case, even worse - randomly with no coherent pattern).

    Just a pet peeve, nothing personal mhtml (or is it MHTML or MHtmL?).

    If you're gonna type everything lower-case, go all the way, lol. Otherwise I'd follow the standard Pascal Casing of VBScript (even though IMHO, especially learning .NET, VBScript syntax stinks).

    Which is why I just got a book that looks like "War and Peace" called "Professional C# Second Edition". C# is a much cleaner language than VB.NET.
    Last edited by whammy; 01-28-2003 at 11:28 PM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #4
    Senior Coder Mhtml's Avatar
    Join Date
    Jun 2002
    Location
    Sydney, Australia
    Posts
    3,531
    Thanks
    0
    Thanked 1 Time in 1 Post
    he he, it was 3am in the morning. I think that getting the coding right at that time was a good effort.

    lol

    Usually my coding style is all uniform.
    Omnis mico antequam dominus Spookster!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •