你可以从Wordpress页面访问POST变量吗?

Mar*_*ios 3 wordpress .htaccess post

我在一个Wordpress页面中用PHP构建了一个联系表单,使用exec-php插件来运行代码.但是,Wordpress重写系统似乎覆盖了发送到页面的POSTed表单数据.有没有办法确保这些数据通过?我所有的,htaccess都是标准的WP重写块.

anu*_*ava 6

是的,您可以在Wordpress页面中访问forrm POST变量.

我创建了一个这样的页面模板:

<?php
/*
Template Name: Page with Form
*/
?>

<?php get_header(); ?>
<div id="content" class="widecolumn">
 <?php
 var_dump($_POST);

 if (have_posts()) : while (have_posts()) : the_post();?>
 <div class="post">
  <h2 id="post-<?php the_ID(); ?>"><?php the_title();?></h2>
  <div class="entrytext">
  <?php the_content('<p class="serif">Read the rest of this page &raquo;</p>');?>
  </div>
 </div>
 <?php endwhile; endif; ?>
 <?php edit_post_link('Edit this entry.', '<p>', '</p>'); ?>
</div>
<form id="test" method="post">
   <input id="srchbox" name="term" size="28" value="" type="text">&nbsp;
   <input name="submit" value="Submit" align="absmiddle" type="submit">
</form>
<?php get_footer(); ?>
Run Code Online (Sandbox Code Playgroud)

然后我通过Wordpress管理面板创建了一个页面,并使用了上面的页面模板.

您可以在此页面模板中看到我有一个示例表单"test".现在,当我在浏览器中访问新创建的页面并在表单中输入一些文本并提交表单时,我得到了这个var_dump($_POST);行:

array(2) {
  ["term"]=>string(7) "foo-bar"
  ["submit"]=>string(6) "Submit"
}
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,Wordpress不会中断任何内容,并且您的页面可以完全访问$_POST阵列POST变量的数组.