2 回答
TA贡献1797条经验 获得超6个赞
非常简单只需要利用$_POST将值传递给变量然后使用它
<?php
$P_email = $_POST['email'];
$P_name = $_POST['name'];
$P_formId = $_POST['formId'];
$P_ip = $_POST['IP'];
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://mkt.university-private.internal/form/submit",
//..hidden
CURLOPT_POSTFIELDS => array('mauticform[f_email]' => $P_email,'mauticform[f_name]' => $P_name,'mauticform[formId]' => $P_formId),
//hidden
//*update* FOR IP
CURLOPT_HTTPHEADER => array(
"X-Forwarded-For: $P_ip"
),
));
//..
更新:所以要解决动态变量名称
//Create an array to hold the name=value pairs
$P_arr = [];
//Loop over $_POST and populate $P_arr
foreach($_POST as $key=>$value){
$P_arr[$key] = $value;
// $key will run through all those keys' values you sent //name ,email ..
// so will $value but on the literals like "gbsilva@40gmail.com", "Gabriel"
}
/* We have now an array of key value pairs */
// adjust the KEYs to "mauticform"'s format before using
$mauticformArr = [];
foreach($P_arr as $key=>$value){
if($key != 'IP'){
if($key!= 'formId')
$mauticformArr['mauticform[f_'.$key .']'] = $value;
else
$mauticformArr['mauticform['.$key .']'] = $value;
}
}
// Then use inside you code as
curl_setopt_array($curl, array(
CURLOPT_URL => "https://mkt.university-private.internal/form/submit",
//..hidden
CURLOPT_POSTFIELDS => $mauticformArr,
//..hidden
//..
- 2 回答
- 0 关注
- 129 浏览
添加回答
举报