I’m using the Bootstrap Multiselect plugin and I can’t figure out how to get the values in php.
Here is my html
<select class="form-control" name="product" multiple>
<option value="a">a</option>
<option value="b">b</option>
<option value="c">c</option>
</select>
here is the entire jquery block
$(document).ready(function() {
$('.home1')
.find('[name="product"]')
.multiselect({
// Re-validate the multiselect field when it is changed
onChange: function(element, checked) {
$('#home1')
.data('bootstrapValidator') // Get plugin instance
.updateStatus('product', 'NOT_VALIDATED') // Update field status
.validateField('product'); // and re-validate it
}
})
.end()
.bootstrapValidator({
excluded: ':disabled',
message: 'This value is not valid',
live: 'disabled',
feedbackIcons: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
submitHandler: function(validator, form, submitButton) {
$.ajax({
type: "POST",
url: "process-step1.php",
data: $('.home1').serialize(),
success: function(msg){
document.location.href = 'form.php';
},
error: function(){
alert("error");
}
});//close ajax
},
fields: {
product: {
validators: {
callback: {
message: 'Please choose 1-5 products',
callback: function(value, validator) {
// Get the selected options
var options = validator.getFieldElements('product').val();
return (options != null && options.length >= 1 && options.length <= 5);
}
}
}
}// product
} // end field
});// bootstrapValidator
}); //ready(function
In the javascript I can get the values by with this…
var options = validator.getFieldElements('product').val();
alert(options);
But how do I then send it to php in my ajax function
$.ajax({
type: "POST",
url: "process-step1.php",
data: $('.home1').serialize(),
success: function(msg){
document.location.href = 'form.php';
},
also once in php how do I get each value?