So I built a form in ASP. Now when I call the page quotes.asp it automatically redirects to the ok.html page immediately and doesnt even load the page. whats wrong with my code? <% ' declare variables Dim EmailFrom Dim EmailTo Dim Subject Dim FirstName Dim LastName Dim Tel Dim State Dim PostCode Dim Comments Dim PaintlessDentRepair Dim AutoDetailing Dim BumperScuffRepair Dim WindshieldReplacement Dim CollisionRepair Dim WindowTinting Dim WheelRimRepair Dim WindshieldRepair Dim PaintScratchChipRepair Dim InteriorRepair Dim HeadlightRenewal Dim OdorRemoval ' get posted data into variables EmailFrom = Trim(Request.Form("EmailFrom")) EmailTo = "mdial1auto@gmail.com" Subject = "New Auto Lead" FirstName = Trim(Request.Form("FirstName")) LastName = Trim(Request.Form("LastName")) Tel = Trim(Request.Form("Tel")) State = Trim(Request.Form("State")) PostCode = Trim(Request.Form("PostCode")) Comments = Trim(Request.Form("Comments")) PaintlessDentRepair = Trim(Request.Form("PaintlessDentRepair")) AutoDetailing = Trim(Request.Form("AutoDetailing")) BumperScuffRepair = Trim(Request.Form("BumperScuffRepair")) WindshieldReplacement = Trim(Request.Form("WindshieldReplacement")) CollisionRepair = Trim(Request.Form("CollisionRepair")) WindowTinting = Trim(Request.Form("WindowTinting")) WheelRimRepair = Trim(Request.Form("WheelRimRepair")) WindshieldRepair = Trim(Request.Form("WindshieldRepair")) PaintScratchChipRepair = Trim(Request.Form("PaintScratchChipRepair")) InteriorRepair = Trim(Request.Form("InteriorRepair")) HeadlightRenewal = Trim(Request.Form("HeadlightRenewal")) OdorRemoval = Trim(Request.Form("OdorRemoval")) ' prepare email body text Dim Body Body = Body & "FirstName: " & FirstName & VbCrLf Body = Body & "LastName: " & LastName & VbCrLf Body = Body & "Tel: " & Tel & VbCrLf Body = Body & "State: " & State & VbCrLf Body = Body & "PostCode: " & PostCode & VbCrLf Body = Body & "Comments: " & Comments & VbCrLf Body = Body & "PaintlessDentRepair: " & PaintlessDentRepair & VbCrLf Body = Body & "AutoDetailing: " & AutoDetailing & VbCrLf Body = Body & "BumperScuffRepair: " & BumperScuffRepair & VbCrLf Body = Body & "WindshieldReplacement: " & WindshieldReplacement & VbCrLf Body = Body & "CollisionRepair: " & CollisionRepair & VbCrLf Body = Body & "WindowTinting: " & WindowTinting & VbCrLf Body = Body & "Wheel/RimRepair: " & WheelRimRepair & VbCrLf Body = Body & "WindshieldRepair: " & WindshieldRepair & VbCrLf Body = Body & "Paint/Scratch&ChipRepair: " & PaintScratchChipRepair & VbCrLf Body = Body & "InteriorRepair: " & InteriorRepair & VbCrLf Body = Body & "HeadlightRenewal: " & HeadlightRenewal & VbCrLf Body = Body & "OdorRemoval: " & OdorRemoval & VbCrLf ' send email Dim mail Set mail = Server.CreateObject("CDONTS.NewMail") mail.To = EmailTo mail.From = EmailFrom mail.Subject = Subject mail.Body = Body mail.Send ' redirect to success page Response.Redirect("ok.htm?" & EmailFrom) %> Code (markup):
Thats what this code says ' redirect to success page Response.Redirect("ok.htm?" & EmailFrom) %> After sending the email, it is redirecting it to success page, could you please be more specific, what do you actually want ?
What you will need to do is to put all of this in a subroutine and call it when posting the email. That way it won't execute on page load but only after posting the form. Else, you could put this all in a processing file to which you post the form.
Isn't that what I just said, only with more detail and better English? Honestly, what's up with folks just popping off responses without adding any value to the thread?
This is not correct, necessarily. You can -- and I belive should -- post forms pages back to themselves, but just handle the events on the server side. Let me know if you need help with this. It's programming 101 IMHO, and this idea of posting to a prcessing script is just lazy and ameture IMHO.
if you really need to sit that code in pageLoad then you could try adding a if postback statement around it, it would then only redirect after the form was called via a post.
Hi this script is wrong because: you define some variable and put some values obtained from a form , but you did not define the form and it should be like this made for example : <% dim strThisPage strThisPage = Request.ServerVariables("SCRIPT_NAME") %> <FORM ACTION="<%= strThisPage %>" METHOD="post" name="EmailForm"> <INPUT TYPE="text" NAME="txtFirstName" VALUE="<%= strFirstName%>" SIZE="25"> <INPUT TYPE="text" NAME="txtLastName" VALUE="<%= strLastName %>" SIZE="25"> ............................ .......................... <INPUT TYPE="submit" VALUE="Submit" name=sub> <INPUT TYPE="reset" VALUE="Reset" > </FORM> action in this form is referer to the same page , you can also define action file to be another page and the targeted page read all values from form , and put it in the mail fields. that's you did it .
Are you actually reading this thead, @palme? I've actually already suggested all of this. Seems some folks are just popping off to get more posts on this forum without actually adding any value to it, IMHO.
After the line: EmailFrom = Trim(Request.Form("EmailFrom")) insert: If EmailFrom <> "" Then around the rest of the code, with an End If at the very end before %>... I might be way off the ball here but that should work