2011-03-26 27 views
0

我想在表單提交(即在sidebar.php上的一個部件)刷新wordpress的sidebar.php。我想刷新表單提交wordpress中的sidebar.php

我在頁面上有視頻,如果整個頁面刷新,視頻必須從頭播放。

我需要一個解決方案來簡單地刷新sidebar.php當有人提交表單...我不是一個專家的PHP程序員這麼簡單是最好的!

btw。我爲表單使用強大的插件。

在此先感謝!

回答

0

聽起來像ajax的工作!

現在,你可以從頭開始,但這會不必要的痛苦。相反,我建議包括jQuery的到你的頁面加入到這一點你的頭

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script> 

(它採用了最新的版本,這是對谷歌託管)

現在,你有jQuery的加載,還有不少好在不中斷事物流的情況下提交數據的方式。這裏是我會怎麼做(我假設你正在使用方法=「郵報」):

  1. 更改<input type="submit" ><button>,所以點擊它不會觸發內置的形式提交(這會中斷你的視頻)。
  2. 將您的按鈕的id屬性設置爲某些內容,以便您可以像<button id="mysubmitbutton">一樣輕鬆地引用它。 (當你在它的時候,如果你還沒有這麼做,你可以輕易地引用它們,如果你還沒有這麼做,那就給所有表單域賦予id屬性,就像<input type="text" name="firstName" id="firstName">而不是)
  3. 在你網站的<head>部分,添加一些代碼,看起來像這樣的事情:

<script type="text/javascript"> 

//makes it so that it goes after the html document is ready for it 

$(document).ready(function() { 

    //this ties a onclick event to your button you made 

    $("#mysubmitbutton").click(function(){ 

    //when the button is clicked, it will asychronously post to where you want it to 

     $.post("urlthatwasinyouractionequalsattribute.php", 

     { 

     //put all your post variables here, referencing the ids you made earlier 

     firstName: $("#firstName").val(), 

     time: $("#time").val() //be sure you don't have a trailing comma on the last one 

     }, 

     function(data) { 

     //data is whatever the other website sends back. do whatever you want here... 

     alert("Result: " + data); 

     }); 

    }); 

}); 

</script> 

火了起來,它應該工作。很顯然,你需要改變這些值,以便它與你的表格等相匹配。

希望對你有所幫助!如果確實如此,請標記爲答案。

+0

這很令人興奮!但是我沒有使用method =「post」。我正在使用插件來創建我的表單,稱爲強大的。 – shelley 2011-03-28 21:32:45

+0

Formidable使用shortode我沒有直接訪問提交按鈕。請問您的解決方案的其餘部分是否能夠刷新sdebar – shelley 2011-03-28 21:35:24

+0

您能看到源代碼嗎?如果是這樣,請發佈。您可能最終不得不放棄強大的代碼,直接轉向代碼以獲得所需的功能(如果這是您的選擇)。 – 2011-03-29 20:47:48