2011-03-26 26 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