2011-10-20 3 views
1

저는 개발중인 Wordpress 플러그 인을 처음 사용합니다. 검색 양식을 디자인했지만 제출 된 양식 데이터를 어디서 처리하고 인쇄해야하는지 잘 모릅니다. 에 의해 (형태 = ""Wordpress 플러그인 폼 문제

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'); 
       } 
    } 
+0

양식에 _action_ 매개 변수가 없습니다. 다른 .php 파일로 보내거나, 액션을 비워두고 같은 페이지/파일/위젯에 $ _POST 데이터를 처리하거나 [AJAX] (http://www.askaboutphp.com/213/php-and- jquery-submit-a-form-without-refresh-the-page.html)을 사용하여 데이터를 처리합니다. –

답변

1
WP에

플러그인은 일반적으로 빈 작용이 있고, 동일한 기능에 처리 : 그것은 여기에 wedget 기반 플러그인과 플러그인 형태 섹션 코드 웨이브 프로 시저 코드가 매우 복잡해지면 OOP를 사용하여 플러그인을 작성하는 편이 낫습니다. 왜냐하면 어쨌든 플러그인이 WP에서 출력되기 전에로드되기 때문입니다. (이것이 왜 ajax 플러그인을 작성하는 것이 wp에서 그렇게 쉬운 지 이유가됩니다). 따라서 다음과 같이 구조화 된 모든 것을 가질 수 있습니다.

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