PHP表单无法在Bootstrap页面中提交?

时间:2016-04-29 20:32:27

标签: javascript php jquery html

我需要一些验证方面的帮助。我在HTML页面中有一个Bootstrap表单 - 还有一个PHP来提交它;但是,当有人点击提交时,页面会被重定向到显示我的PHP代码的位置,并且它实际上并没有提交任何内容。我在某个地方错过了一个剧本吗?

注意:我在AMP HTML中编码。

编辑:我安装了MAMP来测试表单。我点击了提交按钮,现在显示空白页面。

HTML

<form id="submit-form" action="php/sendemail.php" method="POST" class="cf-validation">
<label><h3>Your Name (Required)</h3></label>
    <div class="input-group">
      <input type="text" name="fname" class="form-control">
      <span class="input-group-addon" id="name"><span class="fa fa-user"></span></span>
    </div>

<label><h3>Email (Required)</h3></label>
    <div class="input-group">
      <input type="email" name="senderEmail" class="form-control">
      <span class="input-group-addon" id="email"><span class="fa fa-envelope"></span></span>
    </div>

<label><h3>Phone</h3></label>
    <div class="input-group">
      <input type="phone" name="phone" class="form-control">
      <span class="input-group-addon" id="phone"><span class="fa fa-phone"></span></span>
    </div>

<label><h3>How Can We Help You?</h3></label>
    <div class="single_form"> 
        <select class="selectmenu input-lg form-control" name="category">
            <option selected="selected">Services</option>
            <option>Spa Parties</option>
            <option>Specials</option>
            <option>Other</option>
        </select>
    </div>

<label><h3>Inquiry Details</h3></label>
    <div class="input-group input_group_textarea">
        <textarea name="message" aria-describedby="basic-addon4" class="form-control"></textarea>
        <span class="input-group-addon" id="basic-addon4"><i class="fa fa-comments"></i></span>
    </div>
    <br />
    <button type="submit" class="btn btn-success btn-lg"  style="color:black;">Submit</button>
</form> <!-- End Form -->

PHP

<?php
// Define some constants
define( "RECIPIENT_NAME", "Name" );
define( "RECIPIENT_EMAIL", "email@example.com" );

// Read the form values
$success = false;
$fname = isset( $_POST['fname'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['fname'] ) : "";
$lname = isset( $_POST['lname'] ) ? preg_replace( "/[^\.\-\' a-zA-Z0-9]/", "", $_POST['lname'] ) : "";
$senderEmail = isset( $_POST['email'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['email'] ) : "";
$phone = isset( $_POST['phone'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['phone'] ) : "";
$category = isset( $_POST['category'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['category'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";

$mail_subject = 'A contact request send by ' . $fname. $lname;

$body = 'Name: '. $fname . $lname . "\r\n";
$body .= 'Email: '. $senderEmail . "\r\n";
$body .= 'Phone: '. $phone . "\r\n";
$body .= 'Category: '. $category . "\r\n";
$body .= 'Message: ' . "\r\n" . $message;

// If all values exist, send the email
if ( $fname && $senderEmail && $message ) {
$recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
$headers = "From: " . $fname . $lname . " <" . $senderEmail . ">";  
$success = mail( $recipient, $mail_subject, $body, $headers );
echo "<p class='success'>Thanks for contacting us. We will contact you ASAP!   </p>";
}

?>

脚本

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

2 个答案:

答案 0 :(得分:0)

在apache中启用php模块,确保

LoadModule php5_module modules/libphp5.so

不在apache服务器的httpd.conf文件中发表评论

答案 1 :(得分:-1)

删除这部分代码对我有用:

 action="php/sendemail.php"