我有一个自定义联系人表单,我正试图在其他文件中处理该表单:
表格:
<form method="post" action="<?php echo get_template_directory_uri() . \'/templates/contact.php\' ?>" name="contactform" id="contactform">
<div class="col-sm-6">
<fieldset>
<input name="name" type="text" id="name" size="30" value="" placeholder="Name" />
<br />
<input name="email" type="text" id="email" size="30" value="" placeholder="Email" />
<br />
<input name="phone" type="text" id="phone" size="30" value="" placeholder="Phone" />
<br />
</fieldset>
</div>
<div class="col-sm-6">
<fieldset>
<textarea name="comments" cols="40" rows="8" id="comments" placeholder="Message"></textarea>
<button type="submit" class="btn btn-green-border btn-lg" id="submit" value="submit">Send Message</button>
<input type="hidden" name="address" value="<?php echo $t_one_opt[\'contact_email\'] ?>">
</fieldset>
</div>
</form>
但在处理文件中,我可以实现获取选项值。我正在使用Redux框架,并且在所有站点中都工作得很好。我也加入了全局变量。
联系php
<?php
if(!$_POST) exit;
global $t_one_opt;
$name = $_POST[\'name\'];
$email = $_POST[\'email\'];
$phone = $_POST[\'phone\'];
$comments = $_POST[\'comments\'];
if(trim($name) == \'\') {
echo \'<div class="alert alert-danger text-center">Please enter your name.</div>\';
exit();
} else if(trim($email) == \'\') {
echo \'<div class="alert alert-danger text-center">Please enter a valid email address.</div>\';
exit();
} else if(trim($phone) == \'\') {
echo \'<div class="alert alert-danger text-center">Please enter a valid phone number.</div>\';
exit();
} else if(!is_numeric($phone)) {
echo \'<div class="alert alert-danger text-center">Phone number can only contain digits.</div>\';
exit();
} else if(!isEmail($email)) {
echo \'<div class="alert alert-danger text-center">You have enter an invalid e-mail address,please try again.</div>\';
exit();
}
if(trim($comments) == \'\') {
echo \'<div class="alert alert-danger text-center">Please enter your message.</div>\';
exit();
}
if(get_magic_quotes_gpc()) {
$comments = stripslashes($comments);
}
// Configuration option.
// Enter the email address that you want to emails to be sent to.
// Example $address = "[email protected]";
//$address = "[email protected]";
//global $t_one_opt;
$address = $t_one_opt[\'contact_email\'];
// Configuration option.
// i.e. The standard subject will appear as, "You\'ve been contacted by John Doe."
// Example, $e_subject = \'$name . \' has contacted you via Your Website.\';
$e_subject = \'You\\\'ve been contacted by \' . $name . \'.\';
// Configuration option.
// You can change this if you feel that you need to.
// Developers, you may wish to add more fields to the form, in which case you must be sure to add them here.
$e_body = "You have been contacted by $name with regards to $subject, their additional message is as follows." . PHP_EOL . PHP_EOL;
$e_content = "\\"$comments\\"" . PHP_EOL . PHP_EOL;
$e_reply = "You can contact $name via email, $email or via phone $phone";
$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );
$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;
if(mail($address, $e_subject, $msg, $headers)) {
// Email has sent successfully, echo a success page.
echo "<fieldset>";
echo "<div class=\'alert alert-success text-center\'>";
echo "<h3>Wohoooo ! Well done </h3>";
echo "<p>Thank you <strong>$name</strong>, your message has been submitted to us.</p>";
echo "</div>";
echo "</fieldset>";
} else {
echo \'ERROR!\';
}
它也不识别Wordpress函数。
为什么这个文件在WordPress中“过期”?