我正在尝试使用PHP将多个具有相同名称的复选框值插入CSV,但除非是单个复选框,否则不会填充CSV。
date_default_timezone_set('Europe/London');
$dateNow = date('m/d/Y h:i:s a', time());
$data = [];
$q1ch = implode(",", $_POST["business-related-purchases[]"]); // this is the checkbox I am trying to push into the CSV
$fields = ['contactId', 'date', 'firstName', 'lastName', 'emailAddress',
'companyName', 'q1', $q1ch, 'main-reasons', 'q2', 'sell-promote-radio',
'q3', 'researched-information', 'q4', 'q5', 'tyres-online'
];
foreach ($fields as $field) {
if (isset($_POST[$field])) {
$data[] = trim($_POST[$field]);
// die (print_r ($data[]));
} else {
$data[] = '';
}
}
我尝试了将“与业务相关的购买”直接插入到数组中而不将其放入变量中。
<input value="Banking" type="checkbox" class="banking" name="business-related-purchases">
<input value="Equipment" type="checkbox" name="business-related-purchases">
,这是我的复选框。我也尝试在名称末尾插入[]
,例如name="business-related-purchases[]"