2017-08-16 39 views
1

我試圖在我的wordpress網站上使用smoothstate.js實現聯繫表格7。當使用該頁面的頁面直接加載時,聯繫表單可以很好地工作。但是,如果通過AJAX加載頁面,則會顯示錯誤「wpcf7.initForm不是函數」。通過AJAX(smoothstate.js)加載頁面時,聯繫表格7引發'wpcf7.initForm不是函數'錯誤

我不是AJAX的天才,但我的想法是在AJAX onAfter函數中重新初始化。我通過使用wpcf7InitForm()來試試這個;但仍然沒有運氣。

任何有關這個主題的幫助將不勝感激!

這是我目前的AJAX代碼:

//SmoothState Page Transitions 
 

 
    $(function(){ 
 
    'use strict'; 
 
    var $page = $('#main'), 
 
     options = { 
 
      debug: true, 
 
      prefetch: true, 
 
      onStart: { 
 
      duration: 800, // Duration of our animation 
 
      render: function ($container) { 
 
       // Add your CSS animation reversing class 
 

 
       $container.addClass('is-exiting'); 
 

 
       // Restart your animation 
 
       smoothState.restartCSSAnimations(); 
 
      } 
 
      }, 
 
      onReady: { 
 
       duration: 0, 
 
       render: function($container, $newContent) { 
 
        // Remove your CSS animation reversing class 
 
        $container.addClass('is-loaded'); 
 

 
        setTimeout(function(){ 
 
         $container.addClass('unload'); 
 
        }, 600); 
 

 
        setTimeout(function(){ 
 
         $container.removeClass('is-loaded unload'); 
 
        }, 900); 
 

 

 
        // Inject the new content 
 
        $container.html($newContent); 
 
       } 
 
      }, 
 
      onAfter: function($container) { 
 
       $container.removeClass('is-exiting'); 
 
       $('div.wpcf7 > form').wpcf7InitForm(); 
 
       $(window).data('plugin_stellar').refresh(); 
 
      } 
 
     }, 
 
     smoothState = $("#main").smoothState(options).data("smoothState"); 
 
     });

回答

3

有一個變化在擺脫了jquery.form.js的所以wpcf7InitForm V4.8聯繫表格7(上)功能不再有效。然而,一個新的初始化函數被帶回在v4.8.1

wpcf7.initForm 

使用此功能來代替:

function initContactForm() { 
$('div.wpcf7 > form').each(function() { 
    var $form = $(this); 
    wpcf7.initForm($form); 
    if (wpcf7.cached) { 
    wpcf7.refill($form); 
    } 
}); 
} 

叫它onAfter,它應該解決您的問題。

以下是關於聯繫表7支持論壇的討論: https://wordpress.org/support/topic/init-function-wpcf7initform/