i am using a form validation plugin and in my js file i have this for input and checkbox value pass to json
$('form').submit(function(event) {
$('.form-group').removeClass('has-error'); // remove the error class
$('.help-block').remove(); // remove the error text
var chkbox = new Array();
$('input:checked').each(function() {
chkbox.push(parseint($(this).val()));
});
var formData = {
'company_name': $('input[name=company_name]').val(),
}
$.ajax({
type: 'POST', // define the type of HTTP verb we want to use (POST for our form)
url: 'process.php',
data: formData,chbox,
dataType: 'json',
encode: true
}).done(function(data) {
console.log(data);
if ( ! data.success) {
if (data.errors.company_name) {
$('#company_name-group').addClass('has-error');
$('#company_name-group').append('<div class="help-block">' + data.errors.company_name + '</div>');
Then in php
$errors = array();
$data = array();
if (empty($_POST['company_name']))
$errors['company_name'] = 'Company Name is required.';
if ( ! empty($errors)) {
// if there are items in our errors array, return those errors
$data['success'] = false;
$data['errors'] = $errors;
} else {
$company_name=mysqli_real_escape_string($con,$_POST['company_name']);
$chkbox = $_POST['chkbox'];
$chkNew = "";
foreach($chkbox as $chkNew1)
{
$chkNew .= $chkNew1 . ",";
}
$ins_query="insert into xxx(`company_name`,`Job`)values('company_name','$chkNew');"
retval = mysqli_query( $con , $ins_query);
$data['success'] = true;
$data['message'] = 'Success!';
}
echo json_encode($data);
This work perfectly fine for insert values of form on db values but it stops in my process.php file and doesnt show the message on page .When i remove chkbox from js file form is validated and shows message success in succesfull insertion to db .