Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2016-08-03
4
Medium Priority
?
149 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 1000 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 84

Accepted Solution

by:
Dave Baldwin earned 1000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

886 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