Can you access POST variables from within a Wordpress page?
I built a contact form in PHP inside a Wordpress page, using the exec-php plugin to val and run the code. Howe开发者_Go百科ver, the Wordpress rewrite system seems to override the POSTed form data being sent to the page. Is there any way to ensure that this data gets passed through? All I have in my ,htaccess is the standard WP rewrite block.
Yes you can access forrm POST variables in a page of Wordpress.
I created a page template like this:
<?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 »</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">
<input name="submit" value="Submit" align="absmiddle" type="submit">
</form>
<?php get_footer(); ?>
Then I created a page through Wordpress admin panel and used above page template.
You can see I have a sample form "test" in this page template. Now when I visited the newly created page in my browser and entered some text in form and submitted the form I got this for var_dump($_POST);
line:
array(2) {
["term"]=>string(7) "foo-bar"
["submit"]=>string(6) "Submit"
}
As you can see Wordpress doesn't interrupt anything and your page has full access to your $_POST
array for Form POST variables.
精彩评论