How to catch post array data retrieved from WordPress template page

I started to write my own WordPress plugin. I want to catch data submitted from an HTML form in a custom template page I created. I haven’t a proper idea of how data is handled in WordPress.

This is the code I use in new_page.php file.

Read More
get_header(); ?>

    <div id="primary" class="site-content">
        <div id="content" role="main">

            <?php while ( have_posts() ) : the_post(); ?>
                <?php //get_template_part( 'content', 'page' ); ?>
                <?php// comments_template( '', true ); ?>

        <form name="nn" action="" method="post"></br></br>
            <input type="text" name="test" width="20" />
            <input type="submit" value="Submit" />

        </form>

        <?php testpost();?>
            <?php   endwhile; // end of the loop. ?>



        </div><!-- #content -->
    </div><!-- #primary -->

<?php get_sidebar(); ?>

Here is the code I use in the plugin file to catch post variable data.

ini.php(plugin main page)

function testpost(){

  echo $_post['test'];

}

This code doesn’t do what I need. Can someone guide me to retrieve values from HTML inputs?

Related posts

Leave a Reply

1 comment

  1. After updating above code as follows, I could catch values in plugin.

    <div id="content" role="main">
    
        <?php while ( have_posts() ) : the_post(); ?>
            <?php //get_template_part( 'content', 'page' ); ?>
            <?php// comments_template( '', true ); ?>
    
    <form name="nn" action="<?php echo $_SERVER["REQUEST_URI"]; ?>" method="post"></br></br>
        <input type="text" name="test" width="20" />
        <input type="submit" value="Submit" />
    
    </form>
    
    
        <?php  testpost(); endwhile; // end of the loop. ?>
    
    
    
    </div><!-- #content -->
    

    Though above workaround is worked for my requirement, I am not quite sure whether this is the standard way of handling forms in word-press. Please give your any suggestions and hints if this is not better way to do this.