我下载了一个wordpress模板(http://themes.tvda.eu/demos/identiq/),但我必须搞砸了联系表单,不确定如何。有人可以开导我吗?
如果更容易,它也在https://github.com/fileradar/fileradar.github.io上。
非常感谢
<!-- Start Contact Page -->
<section id="contact" class="page">
<div class="container">
<div class="row">
<div class="span12">
<hr class="feedbackline">
<div class="result">
</div>
</div>
</div>
<!-- Start Form -->
<form class="well">
<div class="row">
<div class="span6 pull-left">
<label>Your name</label>
<input class="span6" type="text" name="name" placeholder="Your Name">
</div>
<div class="span6 pull-right">
<label>Your e-mail</label>
<input class="span6" type="text" name="email" placeholder="Your E-mail">
</div>
</div>
<div class="row">
<div class="span12 textarea-margin">
<label>Message</label>
<textarea class="span12" rows="8" name="message" placeholder="Message"></textarea>
<button type="submit" class="btn"><i class="web-icon">8</i>Send Message</button>
</div>
</div>
</form>
<!-- End Form -->
</div>
</section>
<!-- End Contact Page -->
然后js文件是:
$(function()
{
$("#contact form").submit(function()
{
var form = $(this);
var str = form.serialize();
$.ajax(
{
type: "POST",
url: "contact.php",
data: str,
success: function(msg)
{
$("#contact .result .alert").remove();
msg = JSON.parse(msg);
if(msg.status == 'OK')
{
$('#contact .result').append('<div class="alert alert-success">Your message has been sent. Thank you!</div');
}
else if(msg.text)
{
$.each(msg.text, function(i, elem){
$('#contact .result').append('<div class="alert alert-error">' + elem + '</div');
})
}
else
{
$('#contact .result').append('<div class="alert alert-error">Error</div');
}
}
})
return false;
})
})
并且两个php是:
<?php
function ValidateEmail($email)
{
/*
(Name) Letters, Numbers, Dots, Hyphens and Underscores
(@ sign)
(Domain) (with possible subdomain(s) ).
Contains only letters, numbers, dots and hyphens (up to 255 characters)
(. sign)
(Extension) Letters only (up to 10 (can be increased in the future) characters)
*/
$regex = '/([a-z0-9_.-]+)'. # name
'@'. # at
'([a-z0-9.-]+){1,255}'. # domain & possibly subdomains
'.'. # period
"([a-z]+){2,10}/i"; # domain extension
if($email == '') {
return false;
}
else {
$eregi = preg_replace($regex, '', $email);
}
return empty($eregi) ? true : false;
}
?>
和
<?php
include 'contact_config.php';
error_reporting (E_ALL ^ E_NOTICE);
$post = (!empty($_POST)) ? true : false;
if($post)
{
include 'functions.php';
$name = stripslashes($_POST['name']);
$email = $_POST['email'];
$message = stripslashes($_POST['message']);
$error = array();
// Check name
if(!$name)
{
$error[] = 'Please enter your name.';
}
// Check email
if(!$email)
{
$error[] = 'Please enter an e-mail address.';
}
if($email && !ValidateEmail($email))
{
$error[] = 'Please enter a valid e-mail address.';
}
// Check message (length)
if(!$message || strlen($message) < 15)
{
$error[] = "Please enter your message. It should have at least 15 characters.";
}
if(!$error)
{
$mail = mail(WEBMASTER_EMAIL, $subject, $message,
"From: ".$name." <".$email.">\r\n"
."Reply-To: ".$email."\r\n"
."X-Mailer: PHP/" . phpversion());
mail($to, $message, $headers);
if($mail)
{
echo json_encode(array('status' => 'OK'));
}
else
{
echo json_encode(array('status' => 'error', 'text' => array('Error')));
}
}
else
{
echo json_encode(array('status' => 'error', 'text' => $error));
}
}
?>