我有一个提交调查的表格。表单提交,但是,选中多个复选框并提交表单后,它将在数据库中返回空值。这是用于提交表单的Jquery:
document.addEventListener("DOMContentLoaded", function(event) {
function getUrlQueryParams(url) {
var queryString = url.split("?")[1];
var keyValuePairs = queryString.split("&");
var keyValue = [];
var queryParams = {};
keyValuePairs.forEach(function(pair) {
keyValue = pair.split("=");
queryParams[keyValue[0]] = decodeURIComponent(keyValue[1]).replace(/\+/g, " ");
});
return queryParams;
}
var paramMap = getUrlQueryParams(window.location.href);
// Get the PID and assign it
$(".Form[data-miniform-action='survey']").on('miniform::initialized', function(){
$("input[name='q[2].text']").attr("value", paramMap["pid"]);
});
$(".Form[data-miniform-action='survey']").on('miniform::fieldsAdded', function(){
$("input[name='q[2].text']").attr("value", paramMap["pid"]);
});
// Get the TID and assign it
$(".Form[data-miniform-action='survey']").on('miniform::initialized', function(){
$("input[name='q[3].text']").attr("value", paramMap["tid"]);
});
$(".Form[data-miniform-action='survey']").on('miniform::fieldsAdded', function(){
$("input[name='q[3].text']").attr("value", paramMap["tid"]);
});
// Get the EID and assign it
$(".Form[data-miniform-action='survey']").on('miniform::initialized', function(){
$("input[name='q[4].text']").attr("value", paramMap["eid"]);
});
$(".Form[data-miniform-action='survey']").on('miniform::fieldsAdded', function(){
$("input[name='q[4].text']").attr("value", paramMap["eid"]);
});
});
当提交文件进入数据库时,我看到的唯一错误是,由于将ID和值连接在一起,提交文件似乎为多个选择提供了空值(例如,answerIds_257000,应为answerIds:257000)我有什么办法可以撤销多个ID的串联?