I have a form that submits a survey. The form submits, however, when multiple checkboxes are checked and the form is submitted, it returns a null value in the database. Here is the Jquery used to submit the form:
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"]);
});
});
The only error I see when the submission is in the database is that the submissions seem to give the null values for multiple selections as a result of concatenating the id and the value (e.g. answerIds_257000, when it should be answerIds: 257000) Is there anything I can do to undo the concatenation for multiple Ids?
Aucun commentaire:
Enregistrer un commentaire