因为这个网页不太好,很多杂乱的代码,因此没有用jQuery.
还害得我要弄一个非常简陋的PHP直接提交式的表单. 全部都要自己写.
内容比较简单,就是判断一下POST的数据然后根据情况返回,
这里直接是自己返回页面元素..
代码如下:
<?php
function show_error($str) {
?>
<div class="notification error closeable">
<p><?php echo $str
?></p>
</div>
<?php
}
function show_success($str) {
?>
<div class="notification success closeable">
<p><?php echo $str
?></p>
</div>
<?php
}
if (isset($_POST["name"]) && isset($_POST["email"]) && isset($_POST["phone"])) {
if ($_POST["name"] == "Your name..." || $_POST["email"] == "Your e-mail..." || $_POST["phone"] == "Your phone #") {
show_error("Please fill the form.");
} else {
$error = "";
if (!preg_match("/^[a-zA-Z0-9]{3,20}$/", $_POST["name"])) {
$error.= " Please enter your name.<br />";
}
if (!preg_match("/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $_POST["email"])) {
$error.= " Please enter a valid email.<br />";
}
if (!preg_match("/^([2-9]\d{2}-\d{3}-\d{4}|[2-9]\d{9}|
\d{3}-\d{4})$/", $_POST["phone"])) {
$error.= " Please enter a valid phone number.<br />";
}
if ($error == "") {
$to = "chen@infoempire.com";
$title = "Contact Request - Form [客户名称] " . $_POST['name'];
$headers = 'From: noreply@邮箱地址.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
$msg = 'Name: ' . $_POST['name'] . "\r\n" . 'Phone Number: ' . $_POST['phone'] . "\r\n" . 'Email: ' . $_POST['email'] . "\r\n" . 'IP: ' . $_SERVER["REMOTE_ADDR"] . "\r\n" . "\r\n";
$i = mail($to, $title, $msg, $headers);
if ($i) {
show_success("<span>Thank you!</span> We have got your message.");
} else {
show_error("<span>Sorry</span> Please try later");
}
} else {
show_error($error);
}
}
}
?>