1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

problem with my form

Discussion in 'C#' started by millworx, Oct 27, 2008.

  1. #1
    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.
    SEMrush
    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):
     
    millworx, Oct 27, 2008 IP
    SEMrush
  2. hansab

    hansab Active Member

    Messages:
    162
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #2
    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 ?
     
    hansab, Oct 27, 2008 IP
  3. Sean@WMS

    Sean@WMS Peon

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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.
     
    Sean@WMS, Oct 28, 2008 IP
  4. dinomflorist

    dinomflorist Peon

    Messages:
    16
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    first you must posting form post to this code
     
    dinomflorist, Oct 28, 2008 IP
  5. Sean@WMS

    Sean@WMS Peon

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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?
     
    Sean@WMS, Oct 28, 2008 IP
  6. Sean@WMS

    Sean@WMS Peon

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    Sean@WMS, Oct 28, 2008 IP
  7. wren

    wren Guest

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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.
     
    wren, Oct 30, 2008 IP
  8. palme

    palme Active Member

    Messages:
    320
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #8
    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 .
     
    palme, Nov 3, 2008 IP
  9. Sean@WMS

    Sean@WMS Peon

    Messages:
    134
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #9
    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.

     
    Sean@WMS, Nov 3, 2008 IP
  10. palme

    palme Active Member

    Messages:
    320
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    58
    #10
    yes ,i read it.
     
    palme, Nov 4, 2008 IP
  11. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #11
    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
     
    camjohnson95, Nov 5, 2008 IP