Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Submit form to DB and Email

Options
  • 17-08-2007 2:15pm
    #1
    Registered Users Posts: 782 ✭✭✭


    Hi all,
    I have a number of forms which are submitted directly to a DB with no problems. I also have forms submitted to email again with no problems. Is there a way to submit one form to both a DB and to email same form to an address, e.g. of separate code below:

    DB
    <quote>
    <form name="form" action="add_to_database.asp" method="post">
    CODE
    <input type="submit" value="submit details" onClick="return validForm();" />
    </quote>

    Email
    <quote>
    <form name="frm_booking" action="http://servername/cgi-bin/nmail.pl&quot; method="POST" onSubmit="return validForm(this)">
    <input type=hidden name="to" value="info@domain.com">
    <input type=hidden name="redir" value="http://www.domain.com"&gt;
    <input type=hidden name="subject" value="Registration">
    </quote>

    Any ideas or linkys please, much appreciated!
    Cheers,
    M


Comments

  • Moderators, Politics Moderators Posts: 39,822 Mod ✭✭✭✭Seth Brundle


    yes its easily achieved!
    what language have you in mind?

    edit - I see the form is going to a perl file - somehow merge your code to insert along with your code to send the mail.


  • Registered Users Posts: 782 ✭✭✭gibo_ie


    javascript and asp


  • Moderators, Politics Moderators Posts: 39,822 Mod ✭✭✭✭Seth Brundle


    JavaScript would be client side. You are using ASP and perl on the server.
    Lets go with ASP then.
    insert into database...
    http://www.w3schools.com/ado/default.asp
    send the mail (check if your host supports CDOSYS)...
    http://www.w3schools.com/asp/asp_send_email.asp

    These two would need to be mnerged into one.


  • Registered Users Posts: 782 ✭✭✭gibo_ie


    kbannon wrote:
    JavaScript would be client side. You are using ASP and perl on the server.
    Lets go with ASP then.
    insert into database...
    http://www.w3schools.com/ado/default.asp
    send the mail (check if your host supports CDOSYS)...
    http://www.w3schools.com/asp/asp_send_email.asp

    These two would need to be mnerged into one.

    Please see my original email, i am able to do the two separate but it is mergeing that i have the problem with :(
    Thanks anyway


  • Registered Users Posts: 2,593 ✭✭✭tommycahir


    Hi

    There are a number of options that are available as kbannon said earlier add code to "add_to_database.asp" that will write to the DB as well as sending the mail.

    Another option that I have used in the past is to write a function to add the values to the DB in the page where the form is and then use the onclick event of the submit button to call that function.


  • Advertisement
  • Registered Users Posts: 782 ✭✭✭gibo_ie


    tommycahir wrote:
    Hi

    There are a number of options that are available as kbannon said earlier add code to "add_to_database.asp" that will write to the DB as well as sending the mail.

    Another option that I have used in the past is to write a function to add the values to the DB in the page where the form is and then use the onclick event of the submit button to call that function.
    Thanks,
    Any chance of some sample code so i can get an idea please? I am not a programmer unfortunately but am trying to learn :)


  • Registered Users Posts: 2,593 ✭✭✭tommycahir


    Oops made a mistake in the above post It should say to add some perl code to http://servername/cgi-bin/nmail.pl that will add the data to the DB.

    An example of some perl code to insert values into a DB is located @ http://www.tizag.com/perlT/perlmysqlquery.php


  • Moderators, Politics Moderators Posts: 39,822 Mod ✭✭✭✭Seth Brundle


    gibo_ie wrote:
    Please see my original email, i am able to do the two separate but it is mergeing that i have the problem with :(
    Thanks anyway
    Jeesh - what more can I do? You have code to insert into the database and you have examples of how to do it in ASP. You have code to generate an email in perl and examples of how to do it in ASP. Merging the two should be relatively straight forward (if they are both done using the same language).

    What you need to do is the following:
    1. collect the submitted form data and store each value as a variable e.g. if say 3 items are submitted then using the following will do that
    Dim variable_name1, variable_name2, variable_name3 
    variable_name1 = Request.Form("field_name1") 
    variable_name2 = Request.Form("field_name2") 
    variable_name3 = Request.Form("field_name3")
    
    2. Insert them into your database
    Dim conn, sSQL, sConnString
    'declare SQL statement that will query the database
    sSQL="INSERT INTO my_Table(field1, field2, field3) VALUES ('" & variable_name1 & "', '" & variable_name2 & "', '" & variable_name3 & "')" 
    'define the connection string, specify database 
    'driver and the location of database
    'this assumes its going into MS Access - change it for different database types
    sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _ 
                    "Data Source=" & Server.MapPath("my_database.mdb") 
    'create an ADO connection object
    Set conn = Server.CreateObject("ADODB.Connection")
    'Open the connection to the database
    conn.Open(sConnString)
    'execute the SQL
    connection.execute(sSQL)
    Response.Write "The data was inserted successfully."
    'close the object and free up resources
    conn.Close
    Set conn = Nothing
    
    3. send the email
    Dim myMail, msg
    msg = "This information was just submitted." & vbCrLf & "Variable 1: " & variable_name1  & vbCrLf & "Variable 2: " & variable_name2  & vbCrLf & "Variable 3: " & variable_name3
    Set myMail = CreateObject("CDO.Message")
    myMail.Subject = "Sending email with CDO"
    myMail.From = "mymail@mydomain.com"
    myMail.To = "someone@somedomain.com"
    myMail.TextBody = msg
    myMail.Send
    set myMail = Nothing
    Response.Write "The data has been emailed successfully."
    


Advertisement