1
I have a form that registers the name of the person in a database via ajax, but sometimes delay sending and return and give but 2 or 3 clicks it sends the same data! wanted to know how to stop it, already tried:
<script>
var statSend = false;
function checkSubmit() {
if (!statSend) {
statSend = true;
return true;
} else {
alert("O formulário esta sendo enviado…");
return false; }
}
</script>
and
onclick="this.disabled=true; this.value = 'Aguarde…'; this.form.submit();"
and among others, but none of them worked! someone helps!?
<h4>Cadastro de Nome</h4>
<form id="cadUsuario" method="post">
<label>Nome:</label><input required type="text" name="nome" id="nome" />
<br/><br/>
<input type="submit" value="Salvar" id="salvar" />
</form>
<script type="text/javascript">
$(function () {
$("#cadUsuario").submit(function (e) {
e.preventDefault();
var FormData = $(this).serialize();
$.ajax({
type: "POST",
url: "salvar.php",
dataType: "json", // Add datatype
data: FormData
}).done(function (data) {
$('#cadUsuario').trigger("reset");
var mensagem = '';
if (!data.insert){
mensagem = 'Falha no cadastro';
}
/* if(!data.email){
mensagem += 'Falha no envio do email';
}*/
if(data.insert/* && data.email*/){
mensagem = 'Operação realizda com sucesso';
}
alert(mensagem);
}, "json");
return false;
});
});
</script>
http://stackoverflow.com/questions/926816/how-to-prevent-form-from-submitting-multiple-times-from-client-side
– user60252
Check in php, if this record already exists before inserting it, it could not be?
– LocalHost
is actually there may be two equal names registered, but they can’t have registered by accident you know, fired unintentionally!
– JASL