?
Solved

Sending form information to db and email

Posted on 2005-03-30
29
Medium Priority
?
384 Views
Last Modified: 2008-01-16
Using asp.net:  

I need to create a project request form that once the employee clicks submit after filling out the form
1.  the employee instantenously has a confirmation page on their web browser screen which has the information they entered plus
a message saying "thank you, your project request........."
2.  the data is sent to db
3.  the form/data is emailed to me right away so i can work on project.

Please help.

Thanks.
Victor.
0
Comment
Question by:Padre_Corleone
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 11
  • 9
  • 5
  • +2
29 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 13665262
Ok an overview of what you need:

1.  A basic HTML form for them to fill in

2.  An ASP page that requests the form values and saves to the database and sends an email with CDO (for XP) of CDONTS for anything before,

have a look here for a working example of how to add record to a database:

www.digsixes.co.uk/Add-Del-Update.zip

And here is a basic CDO script, that i normally use to send mail:

<%
'Dimension variables
Dim objCDOSYSCon , objCDOSYSMail, Body  
'Create the e-mail server object
Set objCDOSYSMail = Server.CreateObject("CDO.Message")
Set objCDOSYSCon = Server.CreateObject ("CDO.Configuration")
'Out going SMTP server
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "127.0.0.1"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objCDOSYSCon.Fields.Update

'Update the CDOSYS Configuration
Set objCDOSYSMail.Configuration = objCDOSYSCon

objCDOSYSMail.From = "[b]UserName@DomainName.com[/b]"
objCDOSYSMail.To = "[b]UserName@DomainName.com[/b]"
objCDOSYSMail.Subject = "[b]Your Subject[/b]"

Body = "Dear " + "User"+ ","  
Body = Body + " <html>"
Body = Body + " <body>"
Body = Body + "<p>Your Mail script is working fine."
Body = Body + "...</p> " 
Body = Body + "</body></html> " 

objCDOSYSMail.HTMLBody = Body
objCDOSYSMail.Send

'Close the server mail object
Set objCDOSYSMail = Nothing
Set objCDOSYSCon = Nothing
Response.Write("Your mail was sent")
%>


I know its vague but i thought i would get the ball rolling and let you know what your in for :o)
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13666103
Which server OS?
Which DB and version?
What are the form elements?
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 13676176
I am actuall doing this from a windows 2000 OS with IIS component intalled.  I have a basic html form and I have but I don't follow how to use the asp.net code onto the file in order to be sent a a db and to email it this is what i have basically for now but for simplicity i left many fields that i need out.  ONce they hit submit they can then see a confimation page and be sent to me by email.

<%@ Page Language="VB" %>
<html>
<head>
</head>
<body>
    <form runat="server">
        <form action="ResultPage.aspx" method="Post" name="Myform">
            <table>
                <tbody>
                    <tr>
                        <td>
                            Email:
                        </td>
                        <td>
                            <input type="text" size="50" name="Email" /></td>
                    </tr>
                    <tr>
                        <td>
                            First Name:
                        </td>
                        <td>
                            <input type="text" size="50" name="FirstName" /></td>
                    </tr>
                    <tr>
                        <td>
                            Last Name:
                        </td>
                        <td>
                            <input type="text" size="50" name="LastName" /></td>
                    </tr>
                    <tr>
                        <td>
                            Subject:
                        </td>
                        <td>
                            <input type="text" size="50" name="Subject" /></td>
                    </tr>
                    <tr>
                        <td>
                            Comments:
                        </td>
                        <td>
                            <textarea name="Comments"></textarea>
                        </td>
                    </tr>
                </tbody>
            </table>
            <input type="submit" value="Submit Form" name="Submit" />
        </form>
    </form>
</body>
</html>
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13676982
Ok, I put this together fast, but it should work.

Have a page with the users inputs submit to this page.  You'll need to tweak the names to fit your code.

<html>
<body>

<%
      ' Create variables to hold field values from the form page
      Dim User_Info_1, User_Info_2
      
      ' pull values from Form and preps them for the e-mail
      User_Info_1= "<P><b>Field 1 data:</b> " & Request.Form("Field_1")
      User_Info_2= "<BR><b>Field 2 Data: </b>" & Request.Form("Field_2")

      email = "Your_Address@domain.com"
      
      Dim MailSend
      Set MailSend = Server.CreateObject("CDONTS.NewMail")
      MailSend.From = "ProjectRequest@SomeDomain.com"
      MailSend.Subject = "Re: A Project Request needs to be worked on"
      MailSend.To = email
      MailSend.BodyFormat = 0
      MailSend.Mailformat = 0
      MailSend.Body = User_Info_1 & User_Info_1
      MailSend.Send
       Set MailSend = nothing
      response.write("")
      

' Entering info into the database here
      
DIM adoCon

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open = "DRIVER={SQL Server};SERVER=ServerName;DATABASE=DatabaseName; User ID=UserName; Password=Password;"

' Insert data into the table
adoCon.execute "INSERT into Table_Name(DB_field_1, DB_field_2) VALUES ('" & request.form("Field_1") & "','" & request.form("Field_2")  & "')"

' Close out record set and database connection object
adoCon.Close
Set adoCon = Nothing

%>

<center><b>thank you, your project request has been sent!</b></center>

</BODY>
</HTML>

I hope that helps.
Maurice
0
 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13677037
Sorry, typo...

MailSend.Body = User_Info_1 & User_Info_2
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13677341
GRC... CDOSYS not CDONTS
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13677346
What happened to the database part?  Which database?
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 13683833
i think I am just over whelmed with the coding, i tried it and it didn't work
0
 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13684024
I just realized that you're using asp.net.  I was coding it in asp.

If you're ok with using ASP I'll try to get this working for you.  But I'll need to know the
fields required to be entered by the user.  And I'll need to know the database setup.

ex:

Form fields: First Name, Last Name, e-mail, subject, message
Database Setup: Database Name, Table Name, Field Names

Thanks,
Maurice

0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 13684748
if iam able to use asp for the web form then yeah that would be great!

Form Fields are---->>>>:  

First Name, Last Name, Title (the person requesting project is either a paralegal, secretary, attorney, or accounting)so this could be a drop down list for selection),
Phone Ext (three digits), Project Case Number(5 digits), Project Name, Project Due Date, Special Instructions

Database Setup: ProjectRequest.mdb, Table Name: RequestTable
for field names it would be just like the form fields.

thanks,

let me know if you have anyquestion.

0
 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13684798
ProjectRequest.mdb?  Oh, are you using Microsoft Access for the database?
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 13685389
yeah is that a bad idea?
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 13685394
iam open to any others if suggested to do so, sql right?
0
 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13685765
Well, it really depends on your business requirements.  If this is for a very small office, and the
database isn't going to be seeing many hits in the run of a day, the access database is probably ok.
In any environment where you're expecting the database to get more action, I'd recommend something
a little more reliable.  And you're right, SQL is a good choice.

Getting a SQL Server setup and configured can be a bit of a challenge if you're not familiar though.

The good news is that we can write the code for the Access database.  And if you decided to run
with a SQL database, it would still work.  You'd only need to change 1 line of code. (the database
connection string)

Ok, I'll look into putting something together for you.  But I've had a 16 hour day so I'm calling it quits
for tonight.  I'm back in tommorow though, so I'll see what I can do.

Cheers,
Maurice
0
 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13689960
Hey there,

Ok, let's implement this in two steps.  It'll minimize the troubleshooting.
Let's start off with the form the user fills in, and the page it submits to for sending you the e-mail.
If we get that working, we'll move on to inserting the code for the database.

Copy and paste this code into a file, and name it: Project_Request_form.asp
I've kept it in HTML format so it'll be easy to tweak.

<html>
<head>
<title>Project Request Form</title>
</head>

<body>
<form name="Proj_Form" method="post" action="Project_Request_Confirm.asp">
  <table width="98%" border="0" cellspacing="1" cellpadding="1" bgcolor="#8593B6">
    <tr>
      <td colspan="4">
        <center>
          <b>Project Request Form</b>
        </center>
      </td>
      <td width="54%">&nbsp;</td>
    </tr>
    <tr>
      <td width="15%">
        <div align="right">Title:</div>
      </td>
      <td width="14%">
        <select name="Title">
          <option value="Select a Title">Select a Title</option>            
          <option value="Paralegal">Paralegal</option>
          <option value="Secretary">Secretary</option>
          <option value="Attorney">Attorney</option>
          <option value="Accounting">Accounting</option>
        </select>
      </td>
      <td width="3%">&nbsp;</td>
      <td width="14%">Phone Extension:</td>
      <td width="54%">
        <input type="text" name="Phone_Ext" size="3" maxlength="3">
      </td>
    </tr>
    <tr>
      <td width="15%">
        <div align="right">First Name:</div>
      </td>
      <td width="14%">
        <input type="text" name="First_Name">
      </td>
      <td width="3%">&nbsp;</td>
      <td width="14%">&nbsp;</td>
      <td width="54%">&nbsp;</td>
    </tr>
    <tr>
      <td width="15%">
        <div align="right">Last Name:</div>
      </td>
      <td width="14%">
        <input type="text" name="Last_Name">
      </td>
      <td width="3%">&nbsp;</td>
      <td width="14%">&nbsp;</td>
      <td width="54%">&nbsp;</td>
    </tr>
    <tr>
      <td width="15%">
        <div align="right"></div>
      </td>
      <td width="14%">&nbsp;</td>
      <td width="3%">&nbsp;</td>
      <td width="14%">&nbsp;</td>
      <td width="54%">&nbsp;</td>
    </tr>
    <tr>
      <td width="15%">
        <div align="right">Project Name:</div>
      </td>
      <td width="14%">
        <input type="text" name="Project_Name">
      </td>
      <td width="3%">&nbsp;</td>
      <td width="14%">Project Case #</td>
      <td width="54%">
        <input type="text" name="Project_Case" size="5" maxlength="5">
      </td>
    </tr>
    <tr>
      <td width="15%">
        <div align="right">Project Due Date:</div>
      </td>
      <td width="14%">
        <input type="text" name="Project_Due">
      </td>
      <td width="3%">&nbsp;</td>
      <td width="14%">&nbsp;</td>
      <td width="54%">&nbsp;</td>
    </tr>
    <tr>
      <td width="15%">&nbsp;</td>
      <td width="14%">&nbsp;</td>
      <td width="3%">&nbsp;</td>
      <td width="14%">&nbsp;</td>
      <td width="54%">&nbsp;</td>
    </tr>
    <tr>
      <td width="15%">Special Instructions:</td>
      <td colspan="4">
        <textarea name="Project_Special_Inst" cols="55" rows="4"></textarea>
      </td>
    </tr>
    <tr>
      <td colspan="5">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3">&nbsp;</td>
      <td width="14%">
        <center>
          <input type="submit" name="Submit2" value="Submit">
        </center>
      </td>
      <td width="54%">&nbsp;</td>
    </tr>
  </table>
</form>
        
</body>
</html>
0
 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13689968
Then copy and paste this code into another file, and call it: Project_Request_Confirm.asp

<%@ LANGUAGE="VBScript" %>

<HTML>

<HEAD>
<TITLE>Project Request Submit</TITLE>
</HEAD>
<BODY>
<%

      Dim Title, First_Name, Last_Name, Phone_Ext, Submit_Date, Submit_Time
      Dim Project_Name, Project_Case, Project_Due, Project_Special_Inst
      
      ' pull values from Form and store them in variables
      Submit_Date = "<b>Submit Date:</b> " & FormatDateTime(now,1)
      Submit_Time = "<BR><b>Submit Time:</b> " & time()            
      Title = "<P><b>Title: </b>" & Request.Form("Title")      
      First_Name = "<BR><b>Name: </b>" & Request.Form("First_Name")
      Last_Name = " " & Request.Form("Last_Name")
      Phone_Ext = "<BR><b>Phone Extension: </b>" & Request.Form("Phone_Ext")
      Project_Name = "<P><b>Project Name: </b>" & Request.Form("Project_Name")
      Project_Case = "<BR><b>Project Case Number: </b>" & Request.Form("Project_Case")
      Project_Due = "<BR><b>Project Due Date: </b>" & Request.Form("Project_Due")
      Project_Special_Inst = "<BR><b>Project Special Instructions: </b>" & Request.Form("Project_Special_Inst")      

      email = "maurice.richard@fairmont.com"
      
      Dim MailSend
      Set MailSend = Server.CreateObject("CDONTS.NewMail")
      MailSend.From = "ProjectRequest@YourDomain.com"
    MailSend.Subject = "Re: Project Request"
      MailSend.To = email
      MailSend.BodyFormat = 0
      MailSend.Mailformat = 0
      MailSend.Body = Submit_Date & Submit_Time & Title & First_Name & Last_Name & Phone_Ext & Project_Name & Project_Case & Project_Due & Project_Special_Inst
    MailSend.Send
       Set MailSend = nothing
      response.write("")
      

%>
<center><b>Thank-you, your project request has been sent!</b>
<P>
<a href="Project_Request_Form.asp">Make another project request</a>
</center>
</BODY>
</HTML>
0
 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13689991
That's about it.  

I'm not sure how much you know about ASP so I'll give you the quick basics.
If anything I'm talking about is greek, let me know and I'll expand on it.  Or if you've
got a good understanding of this stuff, nevermind.  :)

You'll need to have IIS installed on the server hosting these files.  And you'll need
to create a virtual directory for the folder containing these files with the Internet
Services Manager tool.  Then just access the Project_Request_Form.asp file through a browser.
And note, double-clicking the file or doing a File --- Open won't work.  You need to:

http://Servername/foldername/subfoldername/Project_Request_Form.asp

I've only tested this with Internet Explorer, but it should give the same result in any browser.
Good luck with this.
Maurice
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 13690667
hey whats up,

looks really good to me.  I did exactly what you asked and when i click on submit i get a Alert windows: Document contains no data.  Any reason why this might be?  maybe i need the database code? iam guessing..

thanks for all your help
0
 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13691888
Ok, I think this is one of 2 things.  I need you to try something for me.
In your browser, go to the tools menu and select internet options.
Click the advanced tab, scroll down and uncheck 'Show Friendly HTTP Error Messages'
Try to run the page again and note the error message.  Actually, I'm assuming
you're running internet explorer... what browser are you using?

Now, let's try an ASP Primer to make sure your IIS is properly setup to run asp pages.
Copy and paste this text into a file, and call it: test.asp

  <%@ Language="VBScript" %>
  <% Option Explicit %>

 <!--- This page should display "ASP is working!" --->

  <!--- if ASP is available to you. --->

  <HTML>
    <HEAD>
      <TITLE>ASP Test Page</TITLE>
    </HEAD>

    <BODY>

      <% Dim TestString %>
      <% TestString = "ASP is Working!" %>

      <H1>

        <% Response.Write TestString %>

      </H1>
    </BODY>
  </HTML>

Run that file the same as before in a browser:
http://Servername/foldername/subfoldername/test.asp

If the browser opens to a page that says "ASP is Working!" then you're IIS is setup ok.
If it's a blank screen, then we'll need to get it configured properly to run the ASP pages.

Let me know.  
Cheers,
Maurice
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 13695411
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30024: Statement is not valid inside a method.

Line 2:    <% Option Explicit %>

this is what I get,??


I've ran other pages using asp.net server code and i have ran other tutorials from my asp.net book and it they run fine with no problems though, so i think that it is working fine.  I also change my setting to "show friendly..." and same thing happened.

thanks
Victor.
0
 
LVL 2

Accepted Solution

by:
GRCHELPDESK earned 500 total points
ID: 13711289
Hey Victor,

Hmm... I'm not sure what to tell you.  I did a copy & paste from what I posted in experts exchange, and the files worked fine for me.  I'm guessing that asp.net server your running doesn't handle standard asp code.  I've been coding ASP for a while, but know very little about asp.net.  

<% Option Explicit %>  -- This forces the declaration of variables used on the page.  If this isn't working ... well, I've never seen that error out before.  It's not necessary, so you can try removing it altogether.  But based on what you're telling me I'd say it's not looking good.

Do you have IIS installed on your server, or does asp.net use something different?
Thanks,
Maurice
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 13711778
yes i have IIS installed correctly, i think your right about asp code not working.  I will give it another shot!  Thanks for all your help!
0
 
LVL 2

Expert Comment

by:GRCHELPDESK
ID: 13711840
Sorry I couldn't be more help.  Good luck with that...
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 13713639
If it's W2K3 then it is not installed by default.  ASP has to be installed.  Only ASP.NET works otherwise.
http://www.w3schools.com/asp/asp_install.asp
0
 
LVL 7

Author Comment

by:Padre_Corleone
ID: 13713957
I followed the step on that site and yes, it worked.  I must be doing something wrong that i get that no data message not that i know asp is working I will keep checking it and will keep you posted!  Thanks.
0
 
LVL 22

Expert Comment

by:WMIF
ID: 14876560
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.  I will make a recommendation to the moderators on its resolution in a week or two.  I appreciate any comments that would help me to make a recommendation.

Unless it is clear to me that the question has been answered I will recommend delete without refund of points.  It is possible that a Grade less than A will be given if no expert makes a case for an A grade.  It is assumed that any participant not responding to this request is no longer interested in its final disposition.

If the user does not know how to close the question, the options are here:
http://www.experts-exchange.com/help.jsp#hs5

WMIF
EE Cleanup Volunteer
0
 
LVL 14

Expert Comment

by:kiddanger
ID: 14877542
Wonder how the Padre is keepin' us posted?
0
 
LVL 22

Expert Comment

by:WMIF
ID: 14930774
I am leaving the following recommendation for this question in the Cleanup topic area:
Accept: GRCHELPDESK

Any objections should be posted here in the next 4 days.  After that time, the question will be closed.

WMIF
EE Cleanup Volunteer
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question