简体   繁体   English

使用send.php在联系人表单上使用Java重定向

[英]Redirect with Javascript on Contact form with send.php

I'm recreating my site and I've included a contact form for users to contact me when needed. 我正在重新创建自己的网站,并提供了联系表格,供用户在需要时与我联系。 I found a javascript that redirects with a countdown timer. 我找到了一个使用倒数计时器重定向的JavaScript。

contact.php: contact.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Contact Form</title>
<meta name="keywords" content="" /> 
<meta name="description" content="" /> 
<link href="tooplate_style.css" rel="stylesheet" type="text/css" />
    <script  src="js/jquery.min.js"></script>
</head>
<div id="tooplate_wrapper">

    <div id="tooplate_header">

        <div id="site_title"><h1><a href="http://deathsrepo.pw">Technologx</a></h1></div>         
        <div id="twitter"><a href="https://twitter.com/Technologx" target="_blank"></a></div>

        <div id="facebook"><a href="https://facebook.com/Technologx2013" target="_blank"></a></div>

        <div id="tooplate_menu">
            <ul>
                <li><a href="index.html">Home</a></li>
                <li><a href="http://deathsrepo.pw/themes.php">Themes</a></li>
                <li><a href="http://blog.deathsrepo.pw">Blog</a></li>
                <li><a href="http://deathsrepo.pw/store.php">Store</a></li>
                <li class="last"></li>
                <li><a href="http://deathsrepo.pw/contact_form.php" class="current">Contact Us</a></li>
                <li class="last"></li>
            </ul>       
        </div> <!-- end of tooplate_menu -->
<style>


body, div, h1,h2, form, fieldset, input, textarea, footer,p {
    margin: 0; padding: 0; border: 0; outline: none;
}


@font-face {
    font-family: 'YanoneKaffeesatzRegular';
    src: url('fonts/yanonekaffeesatz-regular-webfont.eot');
    src: url('fonts/yanonekaffeesatz-regular-webfont.eot?#iefix') format('embedded-opentype'),
    url('fonts/yanonekaffeesatz-regular-webfont.woff') format('woff'),
    url('fonts/yanonekaffeesatz-regular-webfont.ttf') format('truetype'),
    url('fonts/yanonekaffeesatz-regular-webfont.svg#YanoneKaffeesatzRegular') format('svg');
    font-weight: normal;
    font-style: normal;
}

body { font-family: 'YanoneKaffeesatzRegular';}
p {text-shadow:0 1px 0 #fff; font-size:24px;}
#wrap {width:530px; margin:20px auto 0; height:1000px;}
h1 {margin-bottom:20px; text-align:center;font-size:48px; text-shadow:0 1px 0 #ede8d9; }


    #form_wrap { overflow:hidden; height:446px; position:relative; top:0px;
        -webkit-transition: all 1s ease-in-out .3s;
        -moz-transition: all 1s ease-in-out .3s;
        -o-transition: all 1s ease-in-out .3s;
        transition: all 1s ease-in-out .3s;}

    #form_wrap:before {content:"";
        position:absolute;
        bottom:128px;left:0px;
        background:url('images/before.png');
        width:530px;height: 316px;}

    #form_wrap:after {content:"";position:absolute;
        bottom:0px;left:0;
        background:url('images/after.png');
        width:530px;height: 260px; }

    #form_wrap.hide:after, #form_wrap.hide:before {display:none; }
    #form_wrap:hover {height:776px;top:-200px;}


    form {background:#f7f2ec url('images/letter_bg.png'); 
        position:relative;top:200px;overflow:hidden;
        height:200px;width:400px;margin:0px auto;padding:20px; 
        border: 1px solid #fff;
        border-radius: 3px; 
        -moz-border-radius: 3px; -webkit-border-radius: 3px;
        box-shadow: 0px 0px 3px #9d9d9d, inset 0px 0px 27px #fff;
        -moz-box-shadow: 0px 0px 3px #9d9d9d, inset 0px 0px 14px #fff;
        -webkit-box-shadow: 0px 0px 3px #9d9d9d, inset 0px 0px 27px #fff;
        -webkit-transition: all 1s ease-in-out .3s;
        -moz-transition: all 1s ease-in-out .3s;
        -o-transition: all 1s ease-in-out .3s;
        transition: all 1s ease-in-out .3s;}


        #form_wrap:hover form {height:530px;}

        label {
            margin: 11px 20px 0 0; 
            font-size: 16px; color: #b3aba1;
            text-transform: uppercase; 
            text-shadow: 0px 1px 0px #fff;
        }

        input[type=text], textarea {
            font: 14px normal normal uppercase helvetica, arial, serif;
            color: #7c7873;background:none;
            width: 380px; height: 36px; padding: 0px 10px; margin: 0 0 10px 0;
            border:1px solid #f8f5f1;
            -moz-border-radius: 5px; -webkit-border-radius: 5px; border-radius: 5px;
            -moz-box-shadow: inset 0px 0px 1px #726959;
            -webkit-box-shadow:  inset 0px 0px 1px #b3a895; 
            box-shadow:  inset 0px 0px 1px #b3a895;
        }   

        textarea { height: 80px; padding-top:14px;}

        textarea:focus, input[type=text]:focus {background:rgba(255,255,255,.35);}

        #form_wrap input[type=submit] {
            position:relative;font-family: 'YanoneKaffeesatzRegular'; 
            font-size:24px; color: #7c7873;text-shadow:0 1px 0 #fff;
            width:100%; text-align:center;opacity:0;
            background:none;
            cursor: pointer;
            -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; 
            -webkit-transition: opacity .6s ease-in-out 0s;
            -moz-transition: opacity .6s ease-in-out 0s;
            -o-transition: opacity .6s ease-in-out 0s;
            transition: opacity .6s ease-in-out 0s;
        }

        #form_wrap:hover input[type=submit] {z-index:1;opacity:1;
            -webkit-transition: opacity .5s ease-in-out 1.3s;
            -moz-transition: opacity .5s ease-in-out 1.3s;
            -o-transition: opacity .5s ease-in-out 1.3s;
            transition: opacity .5s ease-in-out 1.3s;}

            #form_wrap:hover input:hover[type=submit] {color:#435c70;}

</style>
<body><br /><br /><br /><br />
    <div id="wrap">
        <h1>Contact Form</h1>
        <div id='form_wrap'>
            <form method="post" action="php/send.php">
                <p>Hello Guest,</p>
                <label for="email">Your Message : </label>
                <textarea  name="message" value="Your Message" id="message" ></textarea>    
                <label for="name">Name: </label>
                <input type="text" name="name" value="" id="name" />
                <label for="email">Email: </label>
                <input type="text" name="email" value="" id="email" />
                <input type="submit" name ="submit" value="Send" />
            </form>
        </div>
    </div>
</body>
</html>

Here is the send.php: 这是send.php:

<style>

body {
    margin: 0;
    padding: 0;
    color: #9c9893;
    font-family: Tahoma, Geneva, sans-serif;
    font-size: 13px;
    line-height: 1.7em; 
    background-color: #111212;
    background-image: url(../images/tooplate_body.jpg);
    background-repeat: repeat-x;
    background-position: top center
}
</style>
<script type="text/javascript">
    var count = 5;
    var redirect = "http://test.deathsrepo.pw";

    function countDown(){
        var timer = document.getElementById("timer");
        if(count > 0){
            count--;
            timer.innerHTML = "This page will redirect in "+count+" seconds.";
            setTimeout("countDown()", 1000);
        }else{
            window.location.href = redirect;
        }
    }
    </script>
<?php 
if(isset($_POST['submit'])){
    $to = "deathsarepo@gmail.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $name = $_POST['name'];
    $subject = "Help Needed";
    $subject2 = "Help Needed!";
    $message = $name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Thank you your submission was sent" . $name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

The email function works but the redirection script isn't working it just stays there at the send.php. 电子邮件功能有效,但重定向脚本不起作用,它仅停留在send.php上。 Giving the users the back button option on the browser. 向用户提供浏览器上的后退按钮选项。

I only took a quick look but I didn't see anything that ever fired your countdown timer to start. 我只是快速浏览了一下,但没有发现任何触发您的倒数计时器启动的东西。 Your solution might be as simple as : 您的解决方案可能很简单:

   countDown();
}
</script>

You must change: 您必须更改:

if(isset($_POST['submit'])){
   $to = "deathsarepo@gmail.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $name = $_POST['name'];
    $subject = "Help Needed";
    $subject2 = "Help Needed!";
    $message = $name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Thank you your submission was sent" . $name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
}

with: 与:

  if(isset($_POST['submit'])){
   $to = "deathsarepo@gmail.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $name = $_POST['name'];
    $subject = "Help Needed";
    $subject2 = "Help Needed!";
    $message = $name . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);
    mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
    echo "Thank you your submission was sent" . $name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.

    //new lines
    echo '<div id="timer"></div>';
    echo '<script type="text/javascript">countDown()</script>';
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM