最近有朋友問我WordPress的表單插件 Contact Form 7 怎么實現(xiàn)提交表單后跳轉(zhuǎn)到指定頁面。
經(jīng)過查找資料我發(fā)現(xiàn)之前使用在插件中附加設置中添加 on_send_ok 的方法已經(jīng)停用了。
Note: The method using on_sent_ok hook is no longer recommended. This function is scheduled to be abolished by the end of 2017.
現(xiàn)在 Contact Form 7 采用 custom DOM event 的方式運行 JavaScript。表單提交后跳轉(zhuǎn)到指定url的腳本如下:
<script>
document.addEventListener( 'wpcf7mailsent', function( event ) {
location = 'http://example.com/';
}, false );
</script>
將這段代碼添加到 WordPress 主題的<span id="inline-purple">template</span>文件中。注意,將http://example.com/替換為你想指定跳轉(zhuǎn)的url。
英語好的可以直接點擊下方鏈接查看官方說明。
Redirecting to Another URL After Submissions