Solved

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

Posted on 2016-08-03
4
131 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ASP Error Handler 5 35
JQuery Data Table Default Sort 2 33
center text in div with CSS3 2 30
How to send the email using C# with embedded HTML TABLE 3 24
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

751 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