How to catch data after array extracted from WordPress template page

I started writing my own WordPress plugin. I want to catch data presented from an HTML form on a custom template page that I created. I donโ€™t have the right idea about how data is handled in WordPress.

This is the code I'm using in the 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 that I use in the plugin file to catch the data of the post variable.

ini.php (plugin main page)

 function testpost(){ echo $_post['test']; } 

This code does not do what I need. Can someone help me get values โ€‹โ€‹from HTML inputs?

+4
source share
1 answer

After updating the code above, I could catch the values โ€‹โ€‹in the 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 --> 

Although the above workaround works for my requirement, I'm not quite sure if this is the standard way of handling forms in word-press. Please give your suggestions and tips if this is not the best way to do this.

+1
source

Source: https://habr.com/ru/post/1485558/


All Articles