以下是网站的链接-http://zigzagadvertising.com.ph/aleemguiapal/97-2/
我在wordpress中的表单有问题。每当我点击提交按钮时,它就会返回到索引页,而不是将数据发送到电子邮件地址
This is my PHP code which i placed on top of the Header.php. This code is placed before the tag
<?php
$error=false;
$sent=false;
if(isset($_POST[\'submit\'])) {
if(empty($_POST[\'firstname\']) || empty($_POST[\'email\']) || empty($_POST[\'message\'])) {
$error = true;
} else {
$to = "[email protected]";
$name = trim($_POST[\'firstname\']);
$email = trim($_POST[\'email\']);
$comments = trim($_POST[\'message\']);
$subject = "Contact Form";
$messages = "Name: $firstname \\r\\n Email: $email \\r\\n Comments: $message";
$headers = "From:" . $name;
$mailsent = mail($to, $subject, $messages, $headers);
if($mailsent){
$sent= true;
}
}
}
?>
And this is my custom page(Contact Page)
<!--CONTACT-->
<div class="container">
<div class="eleven columns contact">
<div id="contact-container" class="eleven columns alpha omega contact">
<h2>contact us</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras non lacus vel nulla molestie cursus quis a urna. Donec sodales venenatis consequat. Sed tristique elit nec diam rhoncus adipiscing</p>
</div>
<div id="note-container" class="eleven columns alpha omega note">
<p>All fields marked with an asterisk(<span class="asterisk">*</span>) are required</p>
</div>
<div class="contactform">
<form id="register-form" action="<?php echo $_SERVER[\'PHP_SELF\']; ?>" method="post">
<?php if($error == true) { ?>
<p class="error"> There are some misisng fields.</p>
<?php } if($sent == true) { ?>
<p class="sent">Thank you for sending your message</p><?php } ?>
<div class="four columns alpha contact-form">
<label>prefix</label>
<input type="text" />
<label><span class="asterisk">*</span>first name</label>
<input type="text" name="firstname"/>
<label><span class="asterisk"></span>middle name</label>
<input type="text" name="middlename"/>
<label><span class="asterisk"></span>last name</label>
<input type="text" name="lastname"/>
<label><span class="asterisk">*</span>email address</label>
<input type="text" name="email"/>
</div>
<div class="four columns contact-form">
<label>phone</label>
<input type="text" />
<label>street</label>
<input type="text" />
<label><span class="asterisk"></span>zip</label>
<input type="text" name="zip" />
<label><span class="asterisk"></span>city</label>
<input type="text" name="city" />
</div>
<div class="clearfix"></div>
<div class="eleven columns contact-form alpha omega">
<label><span class="asterisk"></span>subject</label>
<input type="text" name="subject"/>
<label><span class="asterisk">*</span>message</label>
<textarea name="message"></textarea>
<input class="contact-button" type="submit" name="submit" value="submit" />
<input class="contact-button" type="reset" value="reset" />
</div>
</form>
</div>
<div class="four columns">
</div>
</div>
<?php get_sidebar(); ?>
</div>
<?php get_footer(); ?>
</body>
</html>
我试着制作一个联系页面,并将其上传到一个免费的托管站点,它似乎工作正常。我甚至在表格中得到了数据或值。不确定我的表单不能正常工作的原因是否是因为wordpress本身。