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.
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?
After updating above code as follows, I could catch values in plugin.
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.