PROBLEM:
Occasionally users have reported that instead of an ajax submit from happening they end up on http://phppos/.PHP-Point-Of-Sale-Prev/index.php/items/save/1 (with json data showing up to the end user). (This is suppose to be ajax)
I haven't been able to reproduce this myself and am unsure how it is happening.
I am looking for ways to reproduce problem.
You can try the form by going to:
http://demo.phppointofsalestaging.com/
CLICK LOGIN
Then navigate to:
http://demo.phppointofsalestaging.com/index.php/items/view/1/2
HTML
<form action="http://phppos/.PHP-Point-Of-Sale-Prev/index.php/items/save/1" method="post" accept-charset="utf-8" id="item_form" class="form-horizontal" enctype="multipart/form-data">
...
</form>
JS: (in $(document).ready at bottom of page)
$('#item_form').validate(
{
submitHandler:function(form)
{
$.post('http://phppos/.PHP-Point-Of-Sale-Prev/index.php/items/check_duplicate', {term: $('#name').val()},function(data) {
{
doItemSubmit(form);
}} , "json")
.error(function()
{
});
},
errorClass: "text-danger",
errorElement: "span",
highlight:function(element, errorClass, validClass)
{
$(element).parents('.form-group').removeClass('has-success').addClass('has-error');
},
unhighlight: function(element, errorClass, validClass)
{
$(element).parents('.form-group').removeClass('has-error').addClass('has-success');
},
rules:
{
"locations[1][quantity]":
{
number: true
},
"locations[1][reorder_level]":
{
number: true
},
"locations[1][cost_price]":
{
number: true
},
"locations[1][unit_price]":
{
number: true
},
"locations[1][promo_price]":
{
number: true
},
name:"required",
category:"required",
cost_price:
{
required:true,
number:true
},
unit_price:
{
required:true,
number:true
},
promo_price:
{
number: true
},
reorder_level:
{
number:true
},
},
messages:
{
"locations[1][quantity]":
{
number: "This field must be a number"
},
"locations[1][reorder_level]":
{
number: "This field must be a number"
},
"locations[1][cost_price]":
{
number: "This field must be a number"
},
"locations[1][unit_price]":
{
number: "This field must be a number"
},
"locations[1][promo_price]":
{
number: "This field must be a number"
},
name:"Item Name is a required field",
category:"Category is a required field",
cost_price:
{
required:"Cost Price is a required field",
number:"Cost price must be a number"
},
unit_price:
{
required:"Selling Price is a required field",
number:"Unit price must be a number"
},
promo_price:
{
number: "This field must be a number"
}
}
});
});
var submitting = false;
function doItemSubmit(form)
{
if (submitting) return;
submitting = true;
$("#form").mask("Please wait...");
$(form).ajaxSubmit({
success:function(response)
{
$("#form").unmask();
submitting = false;
gritter(response.success ? "Success" +' #' + response.item_id : "Error" ,response.message,response.success ? 'gritter-item-success' : 'gritter-item-error',false,false);
if(response.redirect==1 && response.success)
{
if (response.sale_or_receiving == 'sale')
{
$.post('http://phppos/.PHP-Point-Of-Sale-Prev/index.php/sales/add', {item: response.item_id}, function()
{
window.location.href = 'http://phppos/.PHP-Point-Of-Sale-Prev/index.php/sales'
});
}
else
{
$.post('http://phppos/.PHP-Point-Of-Sale-Prev/index.php/receivings/add', {item: response.item_id}, function()
{
window.location.href = 'http://phppos/.PHP-Point-Of-Sale-Prev/index.php/receivings'
});
}
}
else if(response.redirect==2 && response.success)
{
window.location.href = 'http://phppos/.PHP-Point-Of-Sale-Prev/index.php/items'
}
},
dataType:'json'
});
}