Im running a form in a webshop that looks like this:
<form>
<input type="number" name="quantity" value="" required = "required" />
<input type="radio" name="homeDelivery" value="" required = "required" checked="true" />
<input type="radio" name="homeDelivery" value="" required = "required" />
<input type="submit" value="buy" name="submitBuy" class="buy formConfirm" />
</form>
After the submit button is pressed I run a simple error check in php from the info I get from $_POST. I have an array called $errors, if my error check finds any errors it adds them to my array, else not, and if the array stays empty til the end, my form will submit the data, else not.
I do however want to have a JS confirmbox after pressing submit, that will only popup if there are no errors in the actual form. So to my actual question: Is it possible to check in javascript code if my $errors variable is empty? Something that works like this:
if(empty($errors)) {
//run code
}
If it is possible Id like my javascript code to look something like this(I think you get the idea);
$('.buyConfirm').on('click', function(){
if (errors == NULL) {
return confirm('Are you sure?');
}
else {
return false;
}
});
Any help is appreciated,
Cheers!