2016-12-01 61 views
0

我需要使用聯繫人7有一個嵌入表單,將信息提交給我的Viral Loops帳戶。聯繫表格7:提交javascript的多行

它需要一次表單提交給運行下面的代碼,即on_sent_ok:

VL.options.form_fields.form_firstName = $("#firstname").val(); //capture the first name 
VL.options.form_fields.form_email = $("#email").val(); //capture the email 
VL.options.form_fields.form_lastName = $("#lastname").val(); //capture the last name (if applicable in your form) 
//submit the participant to Viral Loops 
VL.createLead(function() { 
//any logic to run after the participation 
}); 

我不知道在哪裏或如何添加它,因爲您也可以利用一行代碼只有在高級設置中發送確定。

在此先感謝! :)

+1

它不是最易讀的,但爲什麼不把所有的js放在一行呢?分號將關注區分任何一個語句的結束。 –

+0

這或你可以把它作爲一個函數在你已經入隊的外部JS文件(https://developer.wordpress.org/reference/functions/wp_enqueue_script/)並從on_sent_ok調用函數 – Jonathan

回答

2

正如在評論中提到,無論是再壓縮它:

on_sent_ok: "VL.options.form_fields.form_firstName = $('#firstname').val();VL.options.form_fields.form_email = $('#email').val();VL.options.form_fields.form_lastName = $('#lastname').val();VL.createLead(function() {});" 

或者你可以在你的(孩子)的主題目錄中js/script.js創建一個JavaScript文件,然後將其添加到functions.php在你(孩子)的主題目錄:

/** 
* Enqueue a script with jQuery as a dependency. 
*/ 
function so_40916565_enqueue() { 
    wp_enqueue_script('so-40916565', get_stylesheet_directory_uri() . '/js/script.js', array('jquery')); 
} 
add_action('wp_enqueue_scripts', 'so_40916565_enqueue'); 

和新創建的JavaScript文件:

function js_40916565() { 
    VL.options.form_fields.form_firstName = $("#firstname").val(); //capture the first name 
    VL.options.form_fields.form_email = $("#email").val(); //capture the email 
    VL.options.form_fields.form_lastName = $("#lastname").val(); //capture the last name (if applicable in your form) 
    //submit the participant to Viral Loops 
    VL.createLead(function() { 
    //any logic to run after the participation 
    }); 
} 

而且在您的聯繫方式7:

on_sent_ok: "js_40916565();" 

我沒有實際測試過,所以如果它不工作的權利開箱,發表評論。

+0

它不工作:( 如果我JS有這樣的開始? '<?PHP /** * '排隊 如果有幫助,這些都是我接觸7場 '

[文字*姓名佔位符 「名*」]

[text * lastname placeholder'Last Name *「]

[郵件*電子郵件佔位符 「電子郵件地址*」]

[文字*國家佔位符 「國家*」]

[提交的 「發送」]

'我還添加了國家行放入腳本'VL.options.form_fields.form_country = $(「#country」)。val(); //捕捉國家(如果適用於您的表格)' –

+0

不,對不起。也許我的帖子不夠清楚。 'function js_40916565'塊中的代碼應該在你的'js/script.js'文件中,除此之外(除非文件已經存在)。 '用jQuery作爲一個依賴項'阻塞腳本應該在你的'functions.php'文件中,而on_sent_ok顯然應該在WordPress管理員的聯繫表單7中。 – Jonathan

+0

是的,我已經這樣做了,但我使用的是主題選項中的自定義js的Gem主題 - 我在那裏添加了'function'位。 'enqueue'位在我的functions.php文件中,文件中已經有'<?php' - 如果我刪除它,在網站頂部出現錯誤。 '聯繫人7高級設置中的發送好的位。這裏的網頁,如果有幫助[鏈接](http://sportshosts.com/home-13-2) –