首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress插件表单问题

Wordpress插件表单问题
EN

Stack Overflow用户
提问于 2011-10-20 20:46:15
回答 1查看 826关注 0票数 1

我是wordpress插件开发的新手。我设计了一个搜索表单,但是我不知道在哪里处理和打印提交的表单数据。它是一个基于插件的插件,插件表单部分代码如下:

代码语言:javascript
复制
   function widget( $args, $instance ) {
    extract( $args );
        $title = apply_filters( 'widget_title', $instance['title'] );
                $message = apply_filters( 'widget_content', $instance['content'] );
        echo $before_widget;
        //if ( $title )
        //  echo $before_title . $title . $after_title;
        echo '<div class="shk_location_form_holder">
                    <span class="shk_loc_title">'.$title.'
                    <form mthod="post">
                    <input type="text" name="shk_inp_search_locations" id="shk_inp_search_locations" /><br>
                    <div style="height:5px"></div>
                    <input type="submit" Value="Search Locations" />
                    </form></div>';
        echo $after_widget;
                if(isset($_REQUEST['shk_inp_search_locations'])){
                    add_filter('the_content','handle_content');
                }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-12-31 09:52:52

在WP插件中,表单中通常有一个空的action="“,并在同一个函数中处理它(顺便说一句,当wordpress过程代码变得非常混乱时,最好使用OOP编写插件),因为,无论如何,插件都是在WP中输出任何内容之前加载的(这就是为什么在wp中编写ajax插件如此容易的原因)。所以你可以像这样组织所有的东西:

代码语言:javascript
复制
function draw_form() {
    handle_submit();
?>
<div class="shk_location_form_holder">
    <span class="shk_loc_title"><?php echo $title; ?></span>
    <form mthod="post" action="">
        <input type="text" name="shk_inp_search_locations" id="shk_inp_search_locations" /><br>
        <div style="height:5px"></div>
        <input type="submit" Value="Search Locations" />
    </form>
</div>
<?
}

function handle_submit() {
    if(isset($_POST['shk_inp_search_locations']) && $_POST['shk_inp_search_locations'] == 'test') {
        echo 'you may want to end your program here, especially if it\'s ajax!';
        exit;
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7836119

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档