Link to home
Start Free TrialLog in
Avatar of Angel02
Angel02

asked on

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

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
Avatar of Branislav Borojevic
Branislav Borojevic
Flag of Canada image

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?
SOLUTION
Avatar of Manju
Manju
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Angel02
Angel02

ASKER

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.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial