一直试图在Wordpress论坛上提问,但没有点击。我希望这里有更多的人可以帮助我。
我的自定义联系人表单页以前可以使用,但由于某些原因,在我提交表单时会导致404错误。我正在使用自定义永久链接(/%类别%/%postname%/),这以前从来都不是问题。
我从WordPress 3.0开始,我已经更新了几次WordPress,我想知道这些更新是否会导致这种情况。如果没有,会是什么?我仍在处理我的主题,但我已经很长时间没有接触我的联系人页面模板了(我将其与其他页面分离)。
if(isset($_POST[\'submitted\'])) {
if(trim($_POST[\'subject\']) === \'\') {
$subject = \'No subject\';
} else {
$subject = trim($_POST[\'subject\']);
}
if(trim($_POST[\'author\']) === \'\') {
$authorError = \'A valid name is required.\';
$hasError = true;
} else {
$author = trim($_POST[\'author\']);
}
if(trim($_POST[\'email\']) === \'\') {
$emailError = \'A valid email address is required.\';
$hasError = true;
} else if (!preg_match("/^((([a-z]|\\d|[!#$%&\\\'*+\\-\\/=?\\^_`{|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+(\\.([a-z]|\\d|[!#$%&\\\'*+\\-\\/=?\\^_`{|}~]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])+)*)|((\\x22)((((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(([\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]|\\x21|[\\x23-\\x5b]|[\\x5d-\\x7e]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(\\\\\\\\([\\x01-\\x09\\x0b\\x0c\\x0d-\\x7f]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}]))))*(((\\x20|\\x09)*(\\x0d\\x0a))?(\\x20|\\x09)+)?(\\x22)))@((([a-z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-z]|\\d|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.)+(([a-z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])|(([a-z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])([a-z]|\\d|-|\\.|_|~|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])*([a-z]|[\\x{00A0}-\\x{D7FF}\\x{F900}-\\x{FDCF}\\x{FDF0}-\\x{FFEF}])))\\.?$/iu", trim($_POST[\'email\']))) {
$emailError = \'A valid email address is required.\';
$hasError = true;
} else {
$email = trim($_POST[\'email\']);
}
if(trim($_POST[\'message\']) === \'\') {
$messageError = \'A message is required.\';
$hasError = true;
} else {
if(function_exists(\'stripslashes\')) {
$message = stripslashes(trim($_POST[\'message\']));
} else {
$message = trim($_POST[\'message\']);
}
}
if(!isset($hasError)) {
$emailTo = get_option(\'admin_email\');
$subject_send = \'[ from website ] \'.$subject;
$body = "$message";
$headers = \'From: \'.$author.\' <\'.$email.\'>\' . "\\r\\n" . \'Reply-To: \' . $email;
mail($emailTo, $subject_send, $body, $headers);
$emailSent = true;
}
$errorClass = \' class="error"\';
}
还有。。。
<form action="<?php the_permalink(); ?>" id="feedbackform" method="post" novalidate>
<p>
<label for="author">Name</label>
<?php if($authorError != \'\') { ?><label class="error" for="author"><?=$authorError;?></label>
<?php } ?><input id="author" name="author" type="text" value="<?php if(isset($hasError)) echo $_POST[\'author\'];?>" title="Your name is required"<?php if($authorError != \'\') { echo $errorClass; } ?> />
</p>
<p>
<label for="email">Email</label>
<?php if($emailError != \'\') { ?><label class="error" for="email"><?=$emailError;?></label>
<?php } ?><input id="email" name="email" type="email" value="<?php if(isset($hasError)) echo $_POST[\'email\'];?>" title="Your email address is required"<?php if($emailError != \'\') { echo $errorClass; } ?> />
</p>
<p>
<label for="subject">Subject</label>
<input id="subject" name="subject" type="text" value="<?php if(isset($hasError)) echo $_POST[\'subject\'];?>" title="The subject is optional" />
</p>
<p>
<label for="message">Message</label>
<?php if($messageError != \'\') { ?><label class="error" for="message"><?=$messageError;?></label>
<?php } ?><textarea id="message" name="message" title="Your message is required"<?php if($messageError != \'\') { echo $errorClass; } ?>><?php if(isset($hasError)) { if(function_exists(\'stripslashes\')) { echo stripslashes($_POST[\'message\']); } else { echo $_POST[\'message\']; } } ?></textarea>
</p>
<p>
<input id="submit" name="submit" type="submit" value="Send Message" />
<input type="hidden" name="submitted" id="submitted" value="true" />
</p><?php if(isset($emailSent) && $emailSent == true) { ?>
<p>Your message has been sent. I will reply as soon as possile.</p><?php } ?>
</form>