2013-11-27 39 views
0

我有一個表單在我的WordPress頁面上發送提交數據到第三方服務表單提交。表單使用Gravity Forms提交後的API鉤子(http://www.gravityhelp.com/documentation/page/Gform_after_submission),儘管這不是錯誤的原因。傳遞參數add_action和do_action拋出錯誤'第一個參數預計是一個有效的回調'

我已經出現在加載我的網站下面的錯誤由於有我的JavaScript參數傳遞一個問題:

Warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'aoExtPost' was given in /home2/jcollins/public_html/wp-includes/plugin.php on line 429 

我有我的WordPress主題的functions.php文件中:

if (function_exists('load_aoExtPost')) { 
    function load_aoExtPost() { 
     if (!is_admin()) { 
     wp_register_script('ExtPost', get_template_directory_uri() . '/teravoxel/js/ExtPost.js', array(), '0.1', true); 
     wp_enqueue_script('ExtPost'); 
     } 
    } 
} 

//extPostUrl is the argument to pass 
$extPostUrl = 'http://www.---webservice---/eform/3122/0027/d-ext-0002'; 
add_action('gform_after_submission_1', 'ExtPost', 10, 2); 
do_action('gform_after_submission_1', $extPostUrl, $entry); 

這是被引用的JavaScript的內容:

function aoExtPost(extPostUrl) { 
//generate iframe via some echoed out javascript 
var aoUrl = extPostUrl; 
var aoUrlStr = aoUrlA.toString(); 
var aoIfrm = document.createElement('iframe'); 
aoIfrm.setAttribute('id', 'ifrm'); 
aoIfrm.style.display='none'; 
aoIfrm.style.width='0px'; 
aoIfrm.style.height='0px'; 
aoIfrm.src = aoUrlStr; 
document.body.appendChild(aoIfrm); 
}; 

如果我用一個簡單的PHP函數替換上面的JS文件引用,只是爲了測試functions.php中的參數傳遞,它會起作用。有人能告訴我哪裏出錯了嗎?

目的是採取$ extPostUrl的內容,並將其移動到JS生成的iframe的源的查詢字符串(這是我如何將數據傳遞給該第三方服務)

回答

1

由於警告表示,add_action需要一個有效的回調函數。如果傳遞兩個參數掛鉤:

do_action('gform_after_submission_1', $extPostUrl, $entry); 

你可以做的東西(一個或兩個),他們在一個回調函數:

add_action('gform_after_submission_1', 'so20231440_extpost', 10, 2); 
function so20231440_extpost($extPostUrl, $entry) 
{ 
    // do stuff with $extPostUrl and/or $entry 

    // for example: 
    wp_enqueue_script('extpost'); 
    wp_localize_script('extpost', 'extpost', array('url' => $extPostUrl)); 

    // var usage in JS: extpost.url 
} 
相關問題