2017-08-16 2 views
1

私はsmoothstate.jsを使用してWordPressのWebサイトでContact Form 7を実装しようとしています。接触フォームは、それが使用されているページが直接ロードされたときに完全に機能します。ただし、ページがAJAX経由で読み込まれている場合、 'wpcf7.initForm is not a function'というエラーが表示されます。お問い合わせフォーム7 throws 'wpcf7.initFormは関数ではありません。' AJAX(smoothstate.js)を介してページを読み込む際のエラー

私は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

wpcf7InitForm(ようjquery.form.jsを処分したv4.8でフォーム7に連絡する変化)がありました機能はもはや機能しません。しかし、新しい初期化関数は、代わりにこの機能

wpcf7.initForm 

利用v4.8.1に戻した。

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/

関連する問題