【发布时间】:2016-03-08 04:32:46
【问题描述】:
我正在使用 wordpress 安装在 XAMPP 上进行开发。
我的表单看起来不错,一切都是我想要的,但是当我单击提交按钮时,它会加载 index.php 也就是我的网站主页。
所以当我点击提交时,它来自
到
http://localhost/WP/contact/index.php
虽然没有任何信息,但它不应该工作......我尝试按照教程进行操作,所以我迷路了,我仍在学习 JS 和 PHP 的基础知识。
这是我的表单代码
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: $email';
$to = 'alexgray410@gmail.com';
$subject = 'Hello';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
}
?>
<header class="body">
</header>
<section class="body">
<form method="post" action="index.php" class="contact">
<label class="contact">Name</label>
<input name="name" placeholder="Type Here" class="contact">
<label class="contact">Email</label>
<input name="email" type="email" placeholder="Type Here" class="contact">
<label class="contact">Message</label>
<textarea name="message" placeholder="Type Here" class="contact"></textarea>
<label class="contact">*What is 2+2? (Anti-spam)</label>
<input name="human" placeholder="Type Here" class="contact">
<input id="submit" name="submit" type="submit" value="Submit" class="contact">
</form>
</section>
<?php
if(isset($_POST['submit'])){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = 'From: TangledDemo';
$to = 'demo@tangledindesign.com';
$subject = 'Hello';
$human = $_POST['human'];
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if ($_POST['submit']) {
if ($name != '' && $email != '') {
if ($human == '4') {
if (mail ($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
} else if ($_POST['submit'] && $human != '4') {
echo '<p>You answered the anti-spam question incorrectly!</p>';
}
} else {
echo '<p>You need to fill in all required fields!!</p>';
}
}
}
?>
【问题讨论】:
-
您没有在任何地方验证并返回 false 是我通过浏览代码所理解的..
-
任何你可以简化或详细说明的方式,对我来说,我不太了解
标签: php wordpress forms contact