我正在通过 jQuery 通过 .val() 方法收集表单帖子,验证这些帖子并将错误传递回表单输入,或者将 true 传递给调用 PHP cURL 脚本的 .$post 方法。
典型的 var 如下所示:
var industs_servedVal = $('#industs_served').val();
在这种情况下,它是一个选择多个表单字段。我知道 jQuery 中的 .val() 方法传递了一个数组,所以这看起来很合理,我说 var 也会收集数组是对的。
然后我像这样将 var industs_servedVal 传递给 $.post 方法(然后向上滑动感谢信):
$.post('../inc/form_sendsf_modified.php', {
othervars: othervarsVal;
industs_served: industs_servedVal,
}, function(data) {
$('#sendEmail').slideUp('slow', 'swing', function() {
$('#sendEmail').replaceWith('<h3>Thank you!</h3><p>Your message was sent to us. We\'ll get back to you as soon as we can.</p>');
});
});
}
return false;
});
文件“form_sendSF_modified.php”处理这些帖子并使用 cURL 发送到 Sales Force Cloud。这行得通;但是,问题在于销售人员将“数组”显示为接收到的多字段数组的值,而不是数组值本身。我收集阵列并将其传递给销售人员的方式是否存在问题。如代码所示,foreach 循环是否能够将多个字段数组值以及其他值作为数组发送。
$post_data['00N70000002U2fA'] = $_POST['industs_served']; //Array
//$otherpost data
//cURL CODE for post
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection to SFDC
$curl_connection = curl_init('https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);
//show information regarding the request
//print_r(curl_getinfo($curl_connection));
//echo curl_errno($curl_connection) . '-' .
curl_error($curl_connection);
//close the connection
curl_close($curl_connection);
//End cURL