I have a JavaScript array which is taken from a html form which are Checkboxes. I am using name = "DayChosen[]" to get the data into an array that I can pass into to Ajax. I know the data is going into array as I log it into the console, but it just seems to be lost when at the PHP page. I am trying to gather the selected items and open a new page and post the data to this page.
I have tried to encode it to json and then decode it with PHP, but I keep getting a null value. I have tried using JSON also but still did not work.
I have used var_dump to find that i is returning a null value.
<form>
<input type = "checkbox" class="CourseDay" name = "DayChosen[]" value = "Legal"><i class="checkbox-pposition DayChosen">Legal Module</i><br>
<input type = "checkbox" class="CourseDay" name = "DayChosen[]" value = "Day 1"/><i class="checkbox-pposition DayChosen">Day 1</i><br>
<input type = "checkbox" class="CourseDay" name = "DayChosen[]" value = "Rodent"/><i class="checkbox-pposition DayChosen">Day 2 Rodent</i><br>
<input type = "checkbox" class="CourseDay" name = "DayChosen[]" value = "Large animal"><i class="checkbox-pposition DayChosen">Day 2 Large animal </i><br>
<input type = "checkbox" class="CourseDay" name = "DayChosen[]" value = "Aquatic"><i class="checkbox-pposition DayChosen">Day 2 Aquatic</i><br>
<input type = "checkbox" class="CourseDay" name = "DayChosen[]" value = "Wildlife"><i class="checkbox-pposition DayChosen">Day 2 Wildlife</i><br>
<select class="Register-Multiple form-control">
<option disabled selected value > -- Select number of Students to Register -- </option>
<?php
for ($x = 1 ; $x <= 10; $x++) {
echo '<option value = '.$x.'>'.$x.'</option>';
}
?>
</select>
<input type="submit" id = "Register" class="col-6 text-center btn btn-primary Register" value="Register">
</form>
<script type="text/javascript">
$('.Register-Multiple').on('change', function (e){
var courses = [];
$("input[type=checkbox]:checked").each ( function() {
courses.push($(this).val());
console.log($(this).val());
});
$.ajax({
type: "POST",
url: '../../wp-content/themes/traffica/Multiple-
registration.php',
data: {courses:courses}, // serializes the form's elements.
success: function(data)
{
console.log(data);
window.open('../../wp-
content/themes/traffica/Multiple-registration.php');
}
});
});