某些上下文:
我们正在将WP与WPForm和另一个CRM一起使用。我们需要将来自用户的数据存储在WP中,而CRM必须同时获得此数据。
第一种方法,我遇到了这个wp过滤器:
(此示例仅带有演示字段,而不是我的实际字段)
/**
* Integrate WPForms with CRM
*
* @author Bill Erickson
* @link http://www.billerickson.net/contact-form-integration/
*
* @param array $fields
* @param array $entry
* @param array $form_data
* @param int $entry_id
*/
function be_crm_connector( $fields, $entry, $form_data, $entry_id ) {
$api_url = 'http://example.com';
$body = array(
'secret' => '',
'name' => $fields['1']['value'],
'email' => $fields['2']['value'],
'phone' => $fields['3']['value'],
'url' => $fields['4']['value'],
'referral' => $fields['5']['value'],
'referral_other' => $fields['6']['value'],
'services' => $fields['7']['value'],
'date' => date( 'Y-m-d' ),
'inquiry' => $fields['8']['value'],
'status' => '1',
);
$request = wp_remote_post( $api_url, array( 'body' => $body ) );
// Simple error handling
if ( is_wp_error( $request ) ) {
$msg = "There was an error trying to push a lead to the CRM.\n";
$msg .= 'Error returned: ' . $error = $request->get_error_message() . "\n\n";
$msg .= "The lead below may need to be added to the CRM manually.\n";
$msg .= $body['name'] . ' ' . $body['email'];
wp_mail( get_bloginfo( 'admin_email' ), 'CRM Connector Error', $msg );
}
}
add_action( 'wpforms_process_complete_5702', 'be_crm_connector', 10, 4 );
以上实际上是真正的解决方案
然后我放弃了决定以最懒惰的方式做到这一点:
我放置WPForm,然后获取id字段
自动填写表格(CRM表格):
<form class="hidden" method="post" action="https://fancy.url.crm" pageId="878" siteId="66u7u01" parentPageId="147999216" id="WatsonPop" >
<input type="text" name="Nombre" id="control_COLUMN1" label="Nombre" class="textInput defaultText">
<input type="text" name="Apellido" id="control_COLUMN2" label="Apellido" class="textInput defaultText" >
<input type="text" name="Email" id="control_EMAIL" label="Email" class="textInput defaultText" >
<input type="text" name="Mobile" id="control_COLUMN4" label="Celular" class="textInput defaultText" >
<input type="text" name="Pre" id="control_COLUMN3" label="CasinoPreferente" class="textInput defaultText" >
<input type="checkbox" name="Privacidad" id="control_COLUMN6" label="">
<input type="submit" class="defaultText buttonStyle" value="Guardar">
<input type="text" name="ID_R" id="control_COLUMN5">
<input type="hidden" name="formSourceName" value="StandardForm">
<!-- DO NOT REMOVE HIDDEN FIELD sp_exp -->
<input type="hidden" name="sp_exp" value="yes">
</form>
jQuery代码(不幸的是jQuery,我什至不知道如何在VanillaJS中检索正确的值... .innerHTML ?? .value ??)
<script>
$(function(){
var $name = $('#wpforms-7-field_0');
var $nameW = $('#control_COLUMN1');
var $last = $('#wpforms-7-field_0-last');
var $lastW = $('#control_COLUMN2');
var $email = $('#wpforms-7-field_1');
var $emailW = $('#control_EMAIL');
var $tel = $('#wpforms-7-field_4');
var $telW = $('#control_COLUMN4');
var $casino = $('#wpforms-7-field_10');
var $casinoW = $('#control_COLUMN3');
var $tnc = $('#wpforms-7-field_6_1');
var $tncW = $('#control_COLUMN6');
var $id = $('#wpforms-7-field_5');
var $idW = $('#control_COLUMN5');
function onChangeName() {
$nameW.val($name.val());
};
function onChangeLast(){
$lastW.val($last.val());
}
function onChangeEmail(){
$emailW.val($email.val());
}
function onChangeTel(){
$telW.val($tel.val());
}
function onChangeCasino(){
$casinoW.val($casino.val());
}
function onChangeID(){
var href = window.location.search;
if(href.indexOf('/?id=') > -1) {
$id.val('noID');
$idW.val('noID');
} else {
$id.val(href);
$idW.val(href);
}
}
$('#wpforms-7-field_0').change(onChangeName).keyup(onChangeName);
$('#wpforms-7-field_0-last').change(onChangeLast).keyup(onChangeLast);
$('#wpforms-7-field_1').change(onChangeEmail).keyup(onChangeEmail);
$('#wpforms-7-field_4').change(onChangeTel).keyup(onChangeTel);
$('#wpforms-7-field_10').change(onChangeCasino).keyup(onChangeCasino);
$('#wpforms-7-field_10').change(onChangeCasino).keyup(onChangeCasino);
onChangeID();
$tnc.on('change', function(){
$tncW.prop('checked',this.checked);
});
$("#wpforms-submit-7").click(function() {
$.post($("#WatsonPop").attr("action"),
function() {
console.log('Both forms submitted');
});
});
});
</script>
但是没有成功...我再也想不出更好的解决方案了,但是我似乎陷入了试图使Button发送2个表单的方式中。
谢谢