PHP代码无法使用联系表单

时间:2015-04-27 21:48:02

标签: php forms twitter-bootstrap contact

我在一个php文件中创建了一个联系表单,它作为一个独立的php文件工作正常,只有代码,使用bootstrap。它验证数据,发送邮件和工作正常。请看一下:

http://shahsaad.webuda.com/php/contactform.php

问题是,当我尝试在不同的aboutus.php文件中将它包含在我的主页面中时,php代码并不简单。请看一下:

http://shahsaad.webuda.com/aboutus.php

你可以看到它不起作用。我将php代码置于页面中的其他所有内容之上。我应该把它放在其他地方吗?我也试过将它放在体内,但这也不起作用。请有人帮助我。

我在页面顶部输入的PHP代码:

<?php

if($_POST["submit"]) {



    if(!$_POST["name"]) {

        $error = "<br />Please enter your name.";

    }

    if(!$_POST["email"]) {

        $error.="<br />Please enter your email.";

    }

    if(!$_POST["comment"]) {

        $error.="<br />Please enter your comment or query.";

    }

    if ($_POST["email"] AND !filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) { 
        $error.="<br />Please enter a valid email address."; 
    } 

    if($error) {

        $result ='<div class="alert alert-danger"><strong>Error: </strong>'.$error.'</div>';

    } else {

    if (mail("shahsaad@msn.com", "Comment from website!", "Name: ".$_POST['name']."
        Email: ".$_POST['email']."
        Comment: ".$_POST['comment'])) {
        $result='<div class="alert alert-success"><strong>Thank
        you!</strong>We will be in touch.</div>';
    } else {

        $result ='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';

        }

    }
}


    ?>

我的CSS

<style>

    .navbar-brand {

        font-size:1.7em;

    }

    #topContainer {
        background-image:url("background.jpg");
        height:auto;
        width:100%;
        background-size:cover;

    }
    #topRow{
        margin-top:100px;
        color:white;



    }
    #topRow h1{
        font-size:300%;



    }
    .roundDiv{
        border-radius:10px;
        background-color: #ffffff;  
        opacity:0.5;
        color:black;
    }
    .marginTop{
        margin-top:30px;
    }
    .centerDiv{
        text-align:center;

    }
    .title {
        margin-top:100px;
        text-size:300%
    }
    a:hover {
        text-decoration:none;
    }
    .col-md-4{
        text-align:justify;
    }
    #footer {
        background-color:#000000;
        height:40px;
        width:100%;
        text-align:center;
        color:#3777A0;
    }
    .testing{
        width:100%;
        padding-left:27px;
        padding-bottom:20px;
    }
    #emailForm {

    border:1px solid grey;
    border-radius:8px;
    margin-top:10px;
    background-color:#5486a8;
    color:white;
    }

    textarea.form-control {

        height:130px;
    }
    #contactForm {

        padding-bottom:20px;
    }


</style>

我的HTML正文

<body>



    <div class="navbar navbar-inverse navbar-fixed-top">

        <div class="container">

            <div class="navbar-header">

                <button class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                </button>

                <a href="" class="navbar-brand">Soon Valley</a>

            </div>

            <div class="collapse navbar-collapse">

                <ul class="nav navbar-nav">

                    <li><a href="">Photos</a><li>
                    <li><a href="">Videos</a><li>
                    <li><a href="">Notes</a><li>
                    <li><a href="aboutus.php" class="active">About us</a><li>

                </ul>

                <form class="navbar-form navbar-right">

                    <div class="form-group">
                        <input type="email" placeholder="Email" class="form-control"/>
                    </div>

                    <div class="form-group">
                        <input type="password" placeholder="Password" class="form-control"/>
                    </div>

                    <button type="submit" class="btn btn-success">Sign in</button>

                <form>

            </div>

        </div>

    </div>

    <div class="container contentContainer" id="topContainer">

        <div class="row">

        <div class="col-md-6 col-md-offset-3" id="topRow" id="emailForm">

            <h1>Leave us a message..</h1>

            <?php echo $result; ?>


            <p class="lead">Question, comment or concern? Our contact form is the best way to get in touch with us.</p>

            <form method="post" id="contactForm">

                <div class="form-group">

                    <label for="name">Your Name</label>
                    <input type="text" name="name" class="form-control" placeholder="Your Full Name" value="<?php echo $_POST['name']; ?>"/>

                </div>

                <div class="form-group">

                    <label for="email">Your Email</label>
                    <input type="email" name="email" class="form-control" placeholder="Your Email" value="<?php echo $_POST['email']; ?>"/>

                </div>

                <div class="form-group">

                    <label for="comment">Your Comment</label>
                    <textarea name="comment" class="form-control"><?php echo $_POST['comment']; ?></textarea>

                </div>

                <input type="submit" name="submit" class="btn btn-success btn-lg" value="Submit"/>

            </form>

        </div>

    </div>      


    </div>

    <div class="container" id="bottomLinks">

        <div class="row">

            <div class="col-md-4">
                <a href="">
                <h2><span class="glyphicon glyphicon-picture"></span> Photo Gallery</h2>
                </a>
                <p>A brief Description of the photo Gallery, And some more details just to fill this space
                you know.A brief Description of the photo Gallery, And some more details just to fill this space
                you know.</p>


            </div>

            <div class="col-md-4">
                <a href="">
                <h2><span class="glyphicon glyphicon-facetime-video"></span> Videos</h2>
                </a>
                <p>A brief Description of the photo Gallery, And some more details just to fill this space
                you know.A brief Description of the photo Gallery, And some more details just to fill this space
                you know.</p>

            </div>

            <div class="col-md-4">
                <a href="">
                <h2><span class="glyphicon glyphicon-list-alt"></span> Notes</h2>
                </a>
                <p>A brief Description of the photo Gallery, And some more details just to fill this space
                you know.A brief Description of the photo Gallery, And some more details just to fill this space
                you know.</p>

            </div>

        </div>

    </div>

    </div>

    <div class="container" id="footer">

        </p>Designed by: <a href="http://www.facebook.com/shahsaad"><b>Shah Saad Hamadani</b></a>

    </div>



<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<!-- Latest compiled and minified JavaScript -->
<script>

    $(".contentContainer").css("min-height",$(window).height()); 

</script>

0 个答案:

没有答案