Solved

After submitting HTML contact form page redirects to Server Script (ASP/PHP) file in browser

Posted on 2016-08-03
4
79 Views
Last Modified: 2016-08-05
Hi,
When I submit a HTML contact form to get an email with form contents, the page redirects to my email.asp and displays the code in the browser instead of redirecting to Thanks.html page.

Here is the form code in HTML:

<form action="email.asp" name="form1"  id="form1" method="post">

Here is the ASP code:

if not NewMailObj.Send("smtp.yourdomain.com") then
Response.Redirect ("../error.html")
else

Set NewMailObj = nothing
Response.Redirect ("../thanks.html")
end if


How to prevent the page redirect to script and send an email.

Please suggest.

Thank you
0
Comment
Question by:Angel02
4 Comments
 
LVL 4

Expert Comment

by:Branislav Borojevic
ID: 41740878
If you want to redirect after a button is clicked, you can put the code inside your button's OnClick event handler.

Response.Redirect("../thanks.html")

Open in new window


Where did you include the code?

Can you submit the line-by-line code so that I can see what you might be missing?
0
 
LVL 6

Assisted Solution

by:Manju
Manju earned 250 total points
ID: 41740880
Have you installed ASP Components in the IIS server? If not, open Programs and features, click on "Turn Windows features on or off" , Click on IIS (Internet Information Services) -> World Wide Web Services -> Application Development Features -> Check ASP and click ok
0
 

Author Comment

by:Angel02
ID: 41741050
Here is the code for HTML, ASP

Contactpage.html
----------------------------

<script language="javascript">
        function Validating_Form() {
            if (document.getElementById) {
                var i, p, q, nm, test,  errors = '', args = Validating_Form.arguments;
                for (i = 0; i < (args.length - 2); i += 3) {
                    test = args[i + 2]; val = document.getElementById(args[i]);
                    if (val) {
                        nm = val.name; if ((val = val.value) != "") {
                            if (test.indexOf('isEmail') != -1) {
                                p = val.indexOf('@');
                                if (p < 1 || p == (val.length - 1)) errors += '- ' + nm + ' is not valid email address.\n';
                            } 
                        } else if (test.charAt(0) == 'R') errors += '- ' + nm + ' is required.\n';
                    }
                } if (errors) alert('Error\n' + errors);
                document.return_Value = (errors == '');
            }
        }
    </script>

Open in new window



Contact Form:
-------------------

<form action="thanks.asp" name="form1"  id="form1" method="post">
<div class="row">
<div class="col-md-6 form-group">
<label class="sr-only" for="contact-name">Name</label>
<input type="text" name="txtName" placeholder="Name"  
class="contact-name form-control" id="txtName">
</div>
<div class="col-md-6 form-group">
 <label class="sr-only" for="contact-email">Email</label>
 <input type="text" name="txtEmail" placeholder="Email" class="contact-email form-control"
id="txtEmail">
</div>
</div>
<div class="form-group">
<label class="sr-only" for="contact-message">Message</label>
<textarea name="txtMessage" placeholder="Message" class="contact-message form-control" 
id="txtMessage"></textarea>
</div>
                                    
<input name="buttonSend" type="submit" class="btn" id="btnSend" 
onclick="Validating_Form('txtName','','R','txtEmail','','isEmail','txtMessage','','R');return document.return_Value"
value="Submit" />
                                   
                                </form>

Open in new window

                                               



Thanks.asp
----------------
<%@ Language="VBscript" %>
<% Option Explicit %>
<html>
<head>
<title></title>
</head>
<body>
<%
Dim name, email, message, NewMailObj
name=request.form("txtName")
email=request.form("txtEmail")
message=request.form("txtMessage")
Set NewMailObj=Server.CreateObject("JMail.Message")
NewMailObj.Logging = true
NewMailObj.silent = true
NewMailObj.From = email
NewMailObj.FromName = name
NewMailObj.AddRecipient("you@yourdomain.com")
NewMailObj.Subject = "Message from" & name  
NewMailObj.Body = "You have received a message from your company website" & VBCrLf & VBCrLf & "Name: " & name & VBCrLf & "Email: " & email & VBCrLf & "Message: " & message

if not NewMailObj.Send("smtp.yourdomain.com") then
Response.Redirect ("error.html")
else
Set NewMailObj = nothing
Response.Redirect ("thankyou.html")
end if
%> 
</body>
</html> 

Open in new window



Thanks.html:
-------------------
The email has been sent.


When I submit the form, it validates the form and redirects to the Thanks.asp page.
I want it to send an email and redirect to Thanks.html

Please suggest.
Thank you.
0
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 250 total points
ID: 41741252
You don't understand how forms work.  When you have "<form action="email.asp" ", the form is submitted to 'email.asp' and the browser is transferred to 'email.asp' in the process.  If you are seeing the ASP code in your browser then it is not being run on the server and you need to enable Classic ASP on the server.  It is not enabled by default on IIS 7 and higher.
1

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Someone recently asked me about how to display a progress indicator on a page while an iframe is loading. And I remember when I first came across this myself. It was a bit tricky to get my head around, but really, it's very simple. The most impor…
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

770 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