Validate Multidimensional Array before passing to ajax file
I have a form field that is dynamically created in PHP with the following:
- <input type="text" name="subproduct[$i][quantity]" value="0" />
So if there are 5 products from the database the above will repeat 5 times for $i shown above. When someone clicks submit on the form I want to make sure there is at least one of the above with a value greater than "0" being passed in order to submit the form. NOT all of them need to have a value greater than "0" but at least one of them does. Any suggestions? I have been working on this for hours and can't figure this out.
I need this to validate using jQuery before the ajax submit. The ajax code I'm using is below:
- $('#wishlist').submit(function() {
var productvalue = $('#productid').val();
$.ajax({
type: "POST",
url: "includes/add_to_wishlist.php",
data: $('#wishlist').serialize(),
success: showwishlistresponse(productvalue)
})
return false;
});
I appreciate any help on this.