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. However, 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.

Related posts

Leave a Reply

1 comment

  1. 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 &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(); ?>
    

    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.