发布联系表格时我有一个奇怪的问题。
加载图标会继续加载,表单不会提交。
发送电子邮件,我的before_send_mail功能也可以使用。奇怪的是当我取消注释before_send_mail函数时,它没有显示任何错误。所以它可能来自我的代码。
然而,首页不会改变状态并继续显示加载图标。
错误消息sais:
<div class="ajax-error">Unexpected token < in JSON at position 0</div>
当我提交表格时会发生这种情况。
你能帮助我吗?您将在下面找到before_send函数。add_action( 'wpcf7_before_send_mail', 'form_to_crm' );
function form_to_crm( $cf7 ) {
$wpcf7 = WPCF7_ContactForm::get_current();
/* Uw naam => first_name */ $first_name = $_POST["your-name"];
/* Bedrijf => company_name */ $company = $_POST["bedrijf"];
/* Email => email */ $email = $_POST["email"];
/* Adres => address */ $address = $_POST["adres"];
/* Nummer* => number */ $number = $_POST["huisnummer"];
/* Postcode => postcode */ $postcode = $_POST["postcode"];
/* Woonplts* => city */ $city = $_POST["woonplaats"];
/* Tel => telephone */ $telephone = $_POST["telefoonnummer"];
if(!empty( $first_name )){ $post_items['first_name'] = $first_name; }
if(!empty( $company )){ $post_items['company_name'] = $company; }
if(!empty( $email )){ $post_items['email'] = $email; }
if(!empty( $address )){ $post_items['address'] = $address; }
if(!empty( $number )){ $post_items['number'] = $number; }
if(!empty( $postcode )){ $post_items['postcode'] = $postcode; }
if(!empty( $city )){ $post_items['city'] = $city; }
if(!empty( $telephone )){ $post_items['telephone'] = $telephone; }
if(!empty($postcode) && !empty($number))
{
$ch = curl_init();
if ( curl_error($ch) != "" )
{
return;
}
$post_string = json_encode($post_items);
$con_url = 'valid api url';
curl_setopt($ch, CURLOPT_URL, $con_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Token XXX (censored)"
));
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec($ch);
file_put_contents("curlerror.txt", $output);
curl_close($ch);
}
return;
}
答案 0 :(得分:0)
是的我确实找到了答案。相当愚蠢tbh。 在开发工具网络上,当我点击我发送的json请求时,有一个完整的错误消息,显示我从我的联系表单中复制了一个不正确的变量名称。
我复制了[email],而它应该是[你的电子邮件]
希望它可以帮到你!