1 回答

TA貢獻1802條經驗 獲得超5個贊
這就是你所需要的。
在您的主題 functions.php 文件中,您需要添加此 WPForms 操作,這將在您完成并提交表單時觸發。
add_action( 'wpforms_process_complete', 'sendingDataToJava', 10, 4 );
? ?function sendingDataToJava( $fields, $entry, $form_data, $entry_id) {
? ? //Specify WPForm ID you have there
? ? //if form ID is 1
? ? if (form_data[id] == 1) {
? ? ? $api_url = 'http://some java end point.com';
? ? ? $body = array(
? ? ? ? 'name'? ? ? ? ? ? ? ? => $fields['1']['value'],
? ? ? ? 'email'? ? ? ? ? ? ? ?=> $fields['2']['value'],
? ? ? ? 'phone'? ? ? ? ? ? ? ?=> $fields['3']['value'],
? ? ? ?);
? ? ? ?$request = wp_remote_post( $api_url, array( 'body' => $body ) );
? ? ?}
}
您將必須以您使用的形式查看 $fields id,并相應地在上面進行更改。您還需要弄清楚如何獲取 Java 端點文件中的數據。
其他方式
另一種方法是通過在 functions.php 中添加此操作來發出 ajax 請求
add_action( 'wp_ajax_foobar', 'sendingDataToJava' );
add_action( 'wp_ajax_nopriv_foobar', 'sendingDataToJava' );
function sendingDataToJava() {
? ? // do something
? ? // avoids extra 0 at the end of the response
? ? die(); /
}
在您的主題 JS 文件中添加此代碼
jQuery(document).ready(function($) {
? ?$('#form_button_id').click( function() {
? ? ? //
? ? ? var data = {
? ? ? ? ?name: $('#field_1').val(),
? ? ? ? ?email: $('#field_2').val(),
? ? ? ? ?phone: $('#field_3').val()
? ? ? };
? ? ? var ajaxurl = 'http://some java end point.com';
? ? ? jQuery.post(ajaxurl, data, function(response) {
? ? ? ? ?alert('Data Sent to Sent +' response);
? ? ? }
? ? ? );
? ?}
? ?);
}
);
- 1 回答
- 0 關注
- 219 瀏覽
添加回答
舉報