Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add action to ASP form button

Status
Not open for further replies.

Enkrypted

Technical User
Sep 18, 2002
663
US
We have a page that we fill out with customer information. When we submit the form, the information from the form gets input into a SQL database. I was wondering if it is possible to add an action to the submit button without navigating from the current page.

Basically I want this to happen

We input all customer information
We click a button labeled E-mail Confirmation
It takes the info we typed into each field (fields to be sent) and puts it into an outlook e-mail
After we e-mail confirmation to the customer we can submit the form.


Any help with this is appreciated. TIA!

Enkrypted
A+
 
You don't need to use outlook. You can send an email through ASP just before writing the data to the SQL database. you'll just need to collect the information (which you already have for dumping it into SQL) an can use this:


The one I like to use is ASPEMAIL, which is a free component if all you are doing is sending emails, the premium version allows you to send attachments + do encryption and other things...it's made by persits software -



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Thanks for your response vicvirk. I am still new to ASP and coding. I've done some research about this and I have a slight grasp of how it works. I'm just not 100% sure I am doing things properly.

As far as my situation, here are more details about it. The following image is the screen we input information in when we take the customer information:

main.jpg


The following code is for the 2 buttons

Code:
	<CENTER>
	<input type="button" value="Submit" id="btnSubmit" name="btnSubmit" onClick="CheckWholeForm();">
	&nbsp
	&nbsp
	<form name="form1" method="post" action="quoteconfirm.php">
  <input type="submit" name="Submit" value="E-mail Confirmation">
</form>
	</CENTER>

I created a form (quoteconfirm.php) to handle the e-mail portion of it from the link you sent me

Code:
<%

Set oMail = Server.CreateObject("CDO.Message") 
Set oMailConfig = Server.CreateObject ("CDO.Configuration") 

oMailConfig.Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserver")[/URL] = "localhost" 
oMailConfig.Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpserverport")[/URL] = 25 
oMailConfig.Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/sendusing")[/URL] = 1 
oMailConfig.Fields("[URL unfurl="true"]http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout")[/URL] = 60 
oMailConfig.Fields.Update 

Set oMail.Configuration = oMailConfig 
oMail.From = "administrator@sharperimpressionspainting.com"
oMail.To = "test@sharperimpressionspainting.com"
oMail.Subject = "Sharper Impressions Painting Quote Confirmation"
oMail.HTMLBody = "Here goes the email body..."
oMail.Send 

Set oMail = Nothing 
Set oMailConfig = Nothing 

%>

I'm not sure if I am doing the e-mail portion of it correctly. I left the e-mail code as is to test it to see if it worked, but it just submits the form like the other Submit button would instead of e-mailing it.

I'm pretty confident that once I get this e-mail portion of it down, I can find out how to add the form field elements I want to the e-mail.

Enkrypted
A+
 
Encrypted,

Are you using PHP or ASP? This was posted in the ASP forum, but I noticed that your form is submitting to a PHP page....if you are using ASP...

Since you are simply sending a text email you should be able to pull it off with the follwing code. I tried it on my server and it worked.

Code:
<%
Set myMail=CreateObject("CDO.Message")
myMail.Subject="Sending email with CDO"
myMail.From="mymail@mydomain.com"
myMail.To="someone@somedomain.com"
myMail.TextBody="This is a message."
myMail.Send
set myMail=nothing
%>

TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
vicvirk,
i tried that code (without smtpserver, etc.) on our intranet and it didn't work. it gets an error that the web page doesn't display. is there anything that needs added to that code? can it just be placed in a page, and the submit button sends you to that page?
thanks.
 
wvdba,

Is your intranet running ASP? Did you give the file a .asp extension?

The code should not need any adjustments besides changing the "To" field to the email address you are sending to. If you go directly to the page (say you call it "emailTestSend.asp", the page should be blank and an email sent.

Also, there needs to be (IIRC) an SMTP service installed on the machine that sends the email.

You should remove the friendly HTTP messages - it will give you a detailed description of the error, including the line that the error is occuring on. Once you done that, please post the exact error along with the code you are using.

(Method One)



TIP: trying googling the answer before posting, you'll find that more times than not someone else somewhere has had the same request and posted an answer online.
----
I have recently been semi-converted to ensuring all my code (well most of it) works in both javascript and non-javascript enabled browsers
 
Sorry for the delayed response. I've been tied up with meetings etc all day.

As for if I am running ASP, yes we are. I tried PHP to see if it would make any difference but didn't seem to help. I'm not sure if the existing code on the page is redirecting it to the submit function before it has a chance to e-mail the information.

On the regular submit button, it says that on click it goes to the checkwholeform function. I know that it checks to make sure all necessary fields are filled in and then submits it. Here is the code for that:

Code:
 function CheckWholeForm() 
{
  document.QISheetForm.btnSubmit.disabled = true;
  varCheck = true;

  // Check username
  if (document.QISheetForm.QILastName.value == 0)
  {
       alert("Last name cannot be blank.\n");
       document.QISheetForm.QILastName.focus();
       varCheck = false;
  }
  else if ((document.QISheetForm.QIHomeNumber.value == 0) && (document.QISheetForm.QIWorkNumber.value == 0) && (document.QISheetForm.QICellNumber.value == 0))
  {
       alert("You must Enter at least one phone number.\n");
       document.QISheetForm.QIHomeNumber.focus();
       varCheck = false;
  }

  else if (document.QISheetForm.QIMakeApptLater.value == 0)
  {
    if (document.QISheetForm.QIAssignedTo.value == 0)
    {
         alert("Please select someone to assign this QI to.\n");
         document.QISheetForm.QIAssignedTo.focus();
         varCheck = false;
    }
  
    else if (document.QISheetForm.QIScopeOfWork.value == 0)
    {
         alert("Scope Of Work cannot be blank.\n");
         document.QISheetForm.QIScopeOfWork.focus();
         varCheck = false;
    }
    else if (document.QISheetForm.QIAddress1.value == 0)
    {
         alert("Address 1 cannot be blank.\n");
         document.QISheetForm.QIAddress1.focus();
         varCheck = false;
    }

    else if (document.QISheetForm.QICity.value == 0)
    {
         alert("City cannot be blank.\n");
         document.QISheetForm.City.focus();
         varCheck = false;
    }
    else if (document.QISheetForm.QIState.value == 0)
    {
         alert("You must select a State.\n");
         document.QISheetForm.QIState.focus();
         varCheck = false;
    }
  
    else if (isDate(document.QISheetForm.QIApptDate.value) == false)
    {
         //alert("The Appointment Date is not valid.\n");
         document.QISheetForm.QIApptDate.focus();
         varCheck = false;
    }

  }

        
  if (varCheck) 
  {

	 document.QISheetForm.submit();
  } 
  else 
  {
	document.QISheetForm.btnSubmit.disabled = false;  
     return false;

The only other code that I think handles this is located on a different page. Here is some of the code for that:

Code:
<%
If QISheetFormSubmitted = 1 THEN
'Response.Write "QIID: " & QIID
	Response.Write "Adding Customer to the database<br><br>This screen should not appear for more than 30 seconds."
	If Len(QIApptDate) < 1 Or Len(QIApptTime) < 1 Or QIMakeApptLater = 1 THEN
	  QIApptTimeComplete = "Null"
	Else
	  QIApptTimeComplete = "'" & QIApptDate & " " & QIApptTime & "'"
	END IF

[COLOR=red]The code that follows this is the code that throws all the information into the SQL Database, so I will not post all that. The code the follows that is here:[/color]

elseif QISheetFormSubmitted = 2 THEN	

	strFirst=QIFirstName
	firstLen=Len(strFirst)
	strLast=QILastName
	lastLen=Len(strLast)
	strHome=QIHomeNumber
	homeLen=Len(strHome)
	strWork=QIWorkNumber
	workLen=Len(strWork)
	strCell=QICellNumber
	cellLen=Len(strCell)

	
	if homeLen > 1 then
		if firstLen > 1 then
			if lastLen > 1 then
				sqlSTR2 = "Select FirstName,LastName from Customer Where FirstName='" & NoApos(strFirst)& "' and LastName='" & NoApos(strLast) & "' and HomePhone='" & NoApos(strHome) & "'"
			else			
				sqlSTR2 = "Select FirstName,LastName from Customer Where FirstName='" & NoApos(strFirst) & "' and HomePhone='" & NoApos(strHome) & "'"
			end if
		else
			sqlSTR2 = "Select FirstName,LastName from Customer Where HomePhone='" & NoApos(strHome) & "'"
		end if
	elseif workLen > 1 then
		if firstLen > 1 then
			if lastLen > 1 then
				sqlSTR2 = "Select FirstName,LastName from Customer Where FirstName='" & NoApos(strFirst)& "' and LastName='" & NoApos(strLast) & "' and WorkPhone='" & NoApos(strWork) & "'"
			else			
				sqlSTR2 = "Select FirstName,LastName from Customer Where FirstName='" & NoApos(strFirst) & "' and WorkPhone='" & NoApos(strWork) & "'"
			end if
		else
			sqlSTR2 = "Select FirstName,LastName from Customer Where WorkPhone='" & NoApos(strWork) & "'"
		end if
	
	elseif cellLen > 1 then
		if firstLen > 1 then
			if lastLen > 1 then
				sqlSTR2 = "Select FirstName,LastName from Customer Where FirstName='" & NoApos(strFirst)& "' and LastName='" & NoApos(strLast) & "' and CellPhone='" & NoApos(strCell) & "'"
			else			
				sqlSTR2 = "Select FirstName,LastName from Customer Where FirstName='" & NoApos(strFirst) & "' and CellPhone='" & NoApos(strCell) & "'"
			end if
		else
			sqlSTR2 = "Select FirstName,LastName from Customer Where CellPhone='" & NoApos(strCell) & "'"
		end if

	
	elseif firstLen > 1 then
		if lastLen > 1 then
			sqlSTR2 = "Select FirstName,LastName from Customer Where FirstName='" & NoApos(strFirst)& "' and LastName='" & NoApos(strLast) & "'"
		else
			sqlSTR2 = "Select FirstName,LastName from Customer Where FirstName='" & NoApos(strFirst) & "'"
		end if
	elseif lastLen > 1 then
			sqlSTR2 = "Select FirstName,LastName from Customer Where LastName='" & NoApos(strLast) & "'"
	end if
	'response.write sqlStr
	rsA.Open sqlSTR2
	
	
			If NOT rsA.EOF Then
				Session("CustomerFound")="yes"
				rsA.Close
				Response.Redirect("default.asp?page=NEWQI")		
			End IF
	
	Session("CustomerFound")="no"
	Session("CustomerFirst")=QIFirstName
	Session("CustomerLast")=QILastName
	Session("CustomerHome")=QIHomeNumber
	Session("CustomerWork")=QIWorkNumber
	Session("CustomerCell")=QICellNumber
	Response.Redirect("default.asp?page=NEWQI")
	
End If

%>

So somewhere from where the Submit button function is and here, I have to find a way to make it send an e-mail as well.

Enkrypted
A+
 
buncha stuff happened in this thread so i apologize if i doubled up an answer , but to answer the original question :

<CENTER>
<input type="button" value="Submit" id="btnSubmit" name="btnSubmit" onClick="CheckWholeForm();">
&nbsp
&nbsp
<form name="form1" method="post" action="quoteconfirm.php">
<input type="submit" name="Submit" value="E-mail Confirmation">
</form>
</CENTER>

first off.. form within a form, not necessarily a good idea.. secondly make both buttons the same NAME you can still have different ID's reason being depending on which one is clicked it will carry it's VALUE to the response.form

so you can:
request and post all data to DB...
then :
If request.form("submitbtn") = "Email Confirmation" Then ' or whatever the button said
Send email using the code from your other replies here.
end if


you can use the exact same form/data handling structure, just request the submit button(s) by name for thier value which will be the label showing on the button.

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
secondly on producing the actual body of the email you can do it with HTML formatting or plain text, you jus thandle it in both cases as string concatination of the request values and the connecting friendly text like labels


you can be ULTRA lazy on the email portion and :
Code:
Dim emailbody(0) ' i use an array for my possibly large string values.
emailbody(0)
for each element in request.form
  emailbody(0) = emailbody(0) & element& ": " & request.form(element) & vbcrlf & vbcrlf
next

email the content of emailbody(0)

[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
oops!!

Dim emailbody(0) ' i use an array for my possibly large string values.
emailbody(0) [red]= ""[/red]

forgot to type the red in


[thumbsup2]DreX
aKa - Robert
if all else fails, light it on fire and do the happy dance!
" I always think outside the 'box', because I'm never in the 'loop' " - DreX 2005
 
vicvirk, thanks.
the server is running asp. the file has .asp and i run other apps in vb script that run ok but, i have to do it with smtp server mentioned. how would i turn off friendly messages so that it would show the real error, please?
thanks.
 
here's the error message that i'm getting:

CDO.Message.1 error '80040220'
The "SendUsing" configuration value is invalid.
/custom_apps/test9x.asp, line 17

line 17 is:
myMail.Send
am i doing something wrong?
thanks.


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top