Solved

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

Posted on 2016-08-03
4
64 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 82

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Joomla main HTML page 4 49
Powershell output to HTML 1 30
Auto Submit on dropdown box 3 37
Animate a Title 7 37
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
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 to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…

743 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now