How to Process Form Request

时间:2014-01-04 作者:jzeus

所以我在WordPress页面中构建了一个表单,如下所示:

<form action="/help" method="GET">
                        <h2 class="heading post-title">Contact Us</h2>
                        <label>Name:</label><br>
                        <input type="text" name="name" /><br>
                        <label>Email:</label><br>
                        <input type="text" name="email" /><br>
                        <label>Subject:</label><br>
                        <input type="text" name="subject" /><br>
                        <label>Message:</label><br>
                        <textarea name="msg" style="width:200px;height:380px"></textarea><br><br>
                        <input type="submit" style="width:206px;margin:0 auto;border:1px solid gray;border-radius:3px;background-color:orange;color:white" />
                        <br>
                        <label style="color:red"><?php if(isset($_GET[\'success\'])) echo "Your message has successfully been sent!"; else echo "<br>"; ?></label>
                      </form>
和/帮助重定向到包含此代码的同一页面,因此我尝试将该页面重定向到自身
包含上述表单(page help.php)的同一页面,在开始时也包含一些用于处理数据的php,如下所示:

<?php 
if(isset($_POST[\'message\']))
{
 // require \'PHPMailerAutoload.php\';

  $mail = new PHPMailer;

  $mail->isSMTP();                                      // Set mailer to use SMTP
  $mail->Host = \'mail.arkzel.com\';  // Specify main and backup server
  $mail->SMTPAuth = true;                               // Enable SMTP authentication
  $mail->Username = \'[email protected]\';                            // SMTP username
  $mail->Password = \'Xwbs*YR!\';                           // SMTP password
  $mail->SMTPSecure = \'tls\';                            // Enable encryption, \'ssl\' also accepted

  $mail->From = $_POST[\'email\'];;
  $mail->FromName = $_POST[\'name\'];;
  $mail->addAddress(\'[email protected]\');               // Name is optional

  $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
  $mail->isHTML(true);                                  // Set email format to HTML

  $mail->Subject = $_POST[\'subject\'];;
  $mail->Body    = $_POST[\'message\'];
  $mail->AltBody = \'This is the body in plain text for non-HTML mail clients\';

  if(!$mail->send()) {
     echo \'Message could not be sent.\';
     echo \'Mailer Error: \' . $mail->ErrorInfo;
     exit;
  }
  header("location: help?success=1");
}
?>
但是,我得到的是一条404:找不到的消息<非常困惑。

1 个回复
最合适的回答,由SO网友:Milo 整理而成

重命名表单字段,使其不会与WordPress查询变量冲突,特别是name.

保留$_GET$_POST WordPress中的术语:

attachment
attachment_id
author
author_name
calendar
cat
category
category__and
category__in
category__not_in
category_name
comments_per_page
comments_popup
customize_messenger_channel
customized
cpage
day
debug
error
exact
feed
hour
link_category
m
minute
monthnum
more
name
nav_menu
nonce
nopaging
offset
order
orderby
p
page
page_id
paged
pagename
pb
perm
post
post__in
post__not_in
post_format
post_mime_type
post_status
post_tag
post_type
posts
posts_per_archive_page
posts_per_page
preview
robots
s
search
second
sentence
showposts
static
subpost
subpost_id
tag
tag__and
tag__in
tag__not_in
tag_id
tag_slug__and
tag_slug__in
taxonomy
tb
term
theme
type
w
withcomments
withoutcomments
year
资料来源:http://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms

结束

相关推荐

Hide gravity forms

我在我的网站上设置了重力表单,我想根据用户是否已在表单/数据库中发布条目来隐藏/显示表单。如果他们做了一个条目,那么我想隐藏它并显示一些简单的文本。我知道重力形式允许你限制参赛人数,但这并不是我想要的。我猜我必须查询数据库,但我不确定最好的编写方法。我是否需要使用诸如get\\u posts之类的工具来检查作者是否有条目?这是最好的方式吗?