2015-04-06 44 views
1

以下代碼位於wordpress頁面中。我想在wordpress頁面中顯示輸出(Mickey),而不是php頁面

<form action="action_page.php" method="post"> 
    Name:<br> 
    <input type="text" name="name" value="Mickey"> 
    <input type="submit" value="Submit"> 
</form> 

action_page.php

<?php $name=$_POST['name']; echo $name;?> 

我想diplay而不是PHP頁面在一個WordPress頁面輸出(米奇)。請幫幫我。

回答

0

您可以通過AJAX實現它,請參閱codex

添加這的functions.php

add_action('wp_ajax_add_foobar', 'prefix_ajax_add_foobar'); 
add_action('wp_ajax_nopriv_add_foobar', 'prefix_ajax_add_foobar'); 

function prefix_ajax_add_foobar() { 
    // Handle request then generate response using WP_Ajax_Response 

    // In a real world scenario, apply all the validation, 
    // sanitization and black magic to POSTed variables before using them 

    $name=$_POST['name']; 
    echo $name; 
} 

現在按照footer.php可以去的<script>標籤內或在一個單獨的JS文件。

jQuery.post(
    ajaxurl, 
    { 
     'action': 'add_foobar', 
     'data': jQuery("form").sanitize() 
    }, 
    function(response){ 
     alert('The server responded: ' + response);    
    } 
); 

所有的事情都是平等的,你應該看到一個提示值和已發佈的值。

+0

我複製並粘貼它,它不工作。 – david 2015-04-07 16:12:20

相關問題