PHP表单中的提交按钮是不可点击的

时间:2016-05-25 09:42:51

标签: php html button form-submit contacts

问题是提交按钮,它只是无法点击,当我尝试使用表单向自己提交电子邮件时,没有任何事情发生(=屏幕不会改变)。

这是我的代码:

<div class="col-sm-6">
<h4 class="font-alt">Get in touch</h4>
<br>
<form id="contact-form" role="form" novalidate="">
<div class="form-group">
<label class="sr-only" for="cname">Name</label>
<input type="text" id="cname" class="form-control" name="cname"       placeholder="Name*" required="" data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>

<div class="form-group">
<label class="sr-only" for="cemail">Your Email</label>
<input type="email" id="cemail" name="cemail" class="form-control" placeholder="Your E-mail*" required="" data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>

<div class="form-group">
<textarea class="form-control" id="cmessage" name="cmessage" rows="7" placeholder="Message*" required="" data-validation-required-message="Please enter your message."></textarea>
<p class="help-block text-danger"></p>
</div>

<div class="text-center">
<button type="submit" class="btn btn-block btn-round btn-d">Submit</button>
</div>

</form>
<div id="contact-response" class="ajax-response font-alt"></div>
</div>

这是我正在使用的PHP:

<?php
// Mail settings
$to = "info@liannesiemensma.com";
$subject = "Contact form";
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["message"])) {

$content  = "Name: "     . $_POST["name"]    . "\r\n";
$content .= "Email: "    . $_POST["email"]   . "\r\n";
$content .= "Message: "  . "\r\n" . $_POST["message"];

if (mail($to, $subject, $content, $_POST["email"])) {

$result = array(
"message" => "Thanks for contacting me! I will do my best to reply in a timely manner.",
"sendstatus" => 1
);

echo json_encode($result);
} else {

$result = array(
"message" => "Sorry, something is wrong.",
"sendstatus" => 0
);

echo json_encode($result);
}
}
?>

我做错了什么?

3 个答案:

答案 0 :(得分:0)

写表格标签动作=&#34; fileName.php&#34;和方法

例: <form id="contact-form" role="form" novalidate="" action="#" method="post">

答案 1 :(得分:0)

您的表单正好在同一页面上正确提交,只需添加

即可
<?php
print_r($_GET);
?>

在第一行添加此内容并检查

答案 2 :(得分:0)

您在表单声明中缺少一个操作和方法标记,如下例所示:

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

然后你需要用扩展名.php重命名你的文件,并在<?php ?>标签中做一些php处理。您可以使用isset()方法验证字段,如下例所示:

isset($_POST["cname"])