4

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?

4

1 回答 1

1

如下更新上述代码后,我可以在插件中捕获值。

<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 -->

尽管上述解决方法适用于我的要求,但我不太确定这是否是在 word-press 中处理表单的标准方法。如果这不是更好的方法,请提供您的任何建议和提示。

于 2013-06-11T09:54:44.930 回答