1
I am having a problem where by clicking the Cancel button is not canceling the operation and this continuing and sending the form
<form action="insere_forn.php" class="control-form" method="post" id="forn_cad" name="forn_cad" enctype="multipart/form-data">
<div class="row">
<div class="col-6">
<div class="form-group ">
<input type="text" name="nome_forn" placeholder="Digite o nome do fornecedor" class="form-control " id="nome_forn" required/>
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="form-group ">
<input type="text" name="end_forn" placeholder="Endereço" class="form-control " id="end_forn" />
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="form-group ">
<input type="text" name="telefone_forn" placeholder="telefone" class="form-control " id="telefone_forn" />
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="form-group ">
<input type="text" name="email_forn" placeholder="email" class="form-control " id="email_forn" />
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="form-group ">
<input type="text" name="cnpj" placeholder="CNPJ" class="form-control " id="cnpj" />
</div>
</div>
</div>
<div class="row">
<div class="col-6">
<div class="input-group-prepend">
<div class="custom-file">
Arquivo: <input type="file" name="arquivo" class="custom-file-input" id="customFileLang" required accept=".jpg">
<label class="custom-file-label" for="customFileLang">Selecione uma foto</label>
</div>
</div>
</div>
</div>
<div class="form-group">
<input type="hidden" name="id_fornc" value="">
<input type="hidden" name="data_cad_forn" value="">
</div>
<div class="form-group">
<div class="col-6">
<button type="submit" id="butao"class="btn btn-primary">Cadastrar</button>
</div>
</div>
</form>
i am sending the form via ajax
$("#forn_cad").submit(function(e) {
var url2 = "mostra_forn.php";
var url = "insere_forn.php";
if (confirm('Tem certeza que quer cadastrar o Tipo de forncedor?')){
$.ajax({
type: "POST",
url: url,
data: $("#forn_cad").serialize(),
success: function(data)
{
$("#mostra_forn").fadeOut(800, function(){
$("#mostra_forn").load(url2).fadeIn().delay(2000);
});
}
});
}else{
return false
}
e.preventDefault();
});
only that even if I click cancel send the form
upload bar
$(document).ready(function() {
//elements
var progressbox = $('#progressbox');
var progressbar = $('#progressbar');
var statustxt = $('#statustxt');
var submitbutton = $("#butao");
var myform = $("#forn_cad");
var output = $("#output");
var completed = '0%';
$(myform).ajaxForm({
beforeSend: function() {
submitbutton.attr('disabled', '');
statustxt.empty();
progressbox.slideDown(); //exibe a barra de progresso
progressbar.width(completed); //inicia em 0%
statustxt.html(completed); //exibe o texto
statustxt.css('color','#5e72e4'); //define a cor
},
uploadProgress: function(event, position, total, percentComplete) {
progressbar.width(percentComplete + '%') //atualiza o tamanho da barra
statustxt.html(percentComplete + '%'); //atualiza o texto
if(percentComplete>50)
{
statustxt.css('color','#825ee4'); //troca a cor acima dos 50%
}
},
complete: function(response) { // quando completar
output.html(response.responseText); //exibe a resposta do seu arquivo php... podendo ser a imagem carregada
myform.resetForm(); // reseta o form
submitbutton.removeAttr('disabled'); //habilita o botão novamente
progressbox.fadeOut(1000); // esconde a barra
}
});
});
Who it should be
e
on the linee.preventDefault()
? Probably in his console appeared the variable indefinite error.– Woss
Which cancel button?
– LeAndrade
$("#forn_cad"). Ubmit(Function(and) {
– Daniel Ricardo
Friend tries to give e.preventDefault before Return false: e.preventDefault(); Return false;
– Maycon F. Castro
continues sending
– Daniel Ricardo
Dear Daniel, there’s probably something else interfering with the form submission, because in normal cases it’s supposed to work. Just you create a test page and put only this question code and you will see that it will work normally.
– Sam
Another nonsense is to use the action and method attributes in the form if it is sent via Ajax.
– Sam