0
I have a form that I am trying to implement a modal that confirms the Ubmit of this form, but it only appears when I do not enter the required fields, if I type the required fields it goes straight to the action
if anyone can help me I really appreciate
html code
<form id="myForm" data-parsley-validate class="form-horizontal form-label-left" data-toggle="modal" method="POST" action="../Controllers/fecharLocacao.php">
<div class="form-group">
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name">Chegada<span class="required">*</span>
</label>
<div class="col-md-3 col-sm-6 col-xs-12">
<input type="datetime-local" id="last-name" name="chegada" required="required" class="form-control col-md-7 col-xs-12">
</div>
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name">Comb. Chegada<span class="required">*</span>
</label>
<div class="col-md-2 col-sm-6 col-xs-12">
<select class="form-control" name="combchegada">
<option value="1/10">1/10</option>
<option value="2/10">2/10</option>
<option value="3/10">3/10</option>
<option value="4/10">4/10</option>
<option value="5/10">5/10</option>
<option value="6/10">6/10</option>
<option value="7/10">7/10</option>
<option value="8/10">8/10</option>
<option value="9/10">9/10</option>
<option value="10/10">10/10</option>
</select>
</div>
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name">Lavagem<span class="required">*</span>
</label>
<div class="col-md-2 col-sm-6 col-xs-12">
<input type="number" step="any" id="last-name" name="lavagem" class="form-control col-md-3 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name"> Taxa Seguro<span class="required">*</span>
</label>
<div class="col-md-2 col-sm-6 col-xs-12">
<input type="number" step="any" id="last-name" name="txseguro" class="form-control col-md-3 col-xs-12">
</div>
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name">Taxa Aeroporto<span class="required">*</span>
</label>
<div class="col-md-2 col-sm-6 col-xs-12">
<input type="number" step="any" id="last-name" name="txaeroport" class="form-control col-md-3 col-xs-12">
</div>
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name">Lucro cessante<span class="required">*</span>
</label>
<div class="col-md-2 col-sm-6 col-xs-12">
<input type="number" step="any" id="last-name" name="lucrocess" class="form-control col-md-3 col-xs-12">
</div>
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name">Reembolso Despachante<span class="required">*</span>
</label>
<div class="col-md-2 col-sm-6 col-xs-12">
<input type="number" step="any" id="last-name" name="redesp" class="form-control col-md-3 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name">Observações
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" id="last-name" name="obs" class="form-control col-md-3 col-xs-12">
</div>
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name">Km Chegada<span class="required">*</span>
</label>
<div class="col-md-2 col-sm-6 col-xs-12">
<input type="number" id="last-name" name="kmchegada" required="required" class="form-control col-md-3 col-xs-12">
</div>
<input type="hidden" name="id" value="<?php echo $resultado->id; ?>">
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<a href="locacoes.php"><button class="btn btn-round btn-danger" type="button">Cancelar <span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span></button></a>
<button class="btn btn-round btn-warning" type="reset">Resetar <span class="glyphicon glyphicon-repeat" aria-hidden="true"></span></button>
<button type="submit" class="btn btn-round btn-success" data-toggle="modal" data-target="#myModal">Fechar Contrato <span class="glyphicon glyphicon-ok" aria-hidden="true"></span></button></span></button>
</div>
</div>
</form>
Modal
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<form id="submitMyModal">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button for="submitMyModal" type="submit" class="btn btn-primary">Save changes</button>
</form>
</div>
</div>
</div>
</div>
Javascript:
$( "#submitMyModal" ).submit(function( event ) {
event.preventDefault();
});
Since I thank for the help of anyone thanks
Since you don’t submit the form, why not change the Submit button to the normal button? Then you won’t need preventDefault
– Woss
Anderson I want to make the form disappear
– Matheus Mancini
So the same button that submits the form should open the modal? That is, if you are submitting the form, it is expected to go to the action. If you want to open the modal before that, you need to separate things.
– Woss
I don’t understand how to separate, but thanks for trying to help hug
– Matheus Mancini
Start by making the button only open the modal, without submitting the form.
– Woss
Sure you could show me, you know I’m not a programming genius and I’m starting if you can tell me where I delete and where I move where part of the code I appreciate the help
– Matheus Mancini
A button of type "Submit" does the commit, but of type "button" does not.
– Woss
Anderson worked out the modal is appearing without problems, the only problem now is that if I click the modal button it will not go to the action
– Matheus Mancini
The modal is inside the form you want to send?
– Sam
No... sorry guys I’m a novice programmer have patience
– Matheus Mancini
I can see by the code you posted that the modal is inside some form. What form is this? There are 2 Forms on the page?
– Sam
Your modal has a form that seems to be of no use. Remove it and leave your modal inside your original form, so a Ubmit button inside the modal will submit to the desired action.
– Woss
You should mark the answers that solved your problem as accepted, I’ve been looking at other questions of yours and none of them were marked as accepted. See how to mark a response as accepted in https://i.stack.Imgur.com/jx7Ts.png and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252