I need to put a function call on the submit
button, which checks if there is at least one file in the database and if it does not, do not let the form be submitted.
I need to put a function call on the submit
button, which checks if there is at least one file in the database and if it does not, do not let the form be submitted.
You will need a AJAX
call to the server to check whether or not the database entry exists. The return of this call can be a JSON
that indicates that the entry exists or not.
Generic code of what you can do. I think you can adapt.
$('input[type="submit"]').on('click',function(e){
e.prenventDefault(); // previne form de ser submitado
$.get(
'controlador.php', // código em php que recebe chamada ajax
{
data : dados // eventuais dados
},
function(resposta){
if (resposta.temEntrada){
$('#formId').submit(); // submita form de id 'formId'
}else{
// faz outra coisa
}
}
);
});
You should go via AJAX to check if there is a record in the database. In return you submit the form or not.
Or you can submit, verify, and if there is no record you blow an exception.
There are several ways to solve your problem, I would particularly opt for ajax. I would send everything via ajax.