hidemodal if a response variable is 1
HI at all , sorry for english.
I have a modal to insert data in a db , the workflow is correct and data are saved in db .
this is the jquery code :
- $(document).ready(function () {
-
-
- $("#insert_cliente").click(function(){
-
- $('#ClientiModal').modal('show');
- });
-
- $("#button_insert_client").click(function(){
-
- var name_modal = $("#id_class_nome_modal").val();
- var surname_modal = $("#id_class_cognome_modal").val();
- var telephone_modal = $("#id_class_telefono_modal").val();
-
-
- $.ajax({
- type: "POST",
- url: "../../common/insert_client_modal.php",
- data: "nome_modal="+name_modal+
- "&cognome_modal="+surname_modal+
- "&telefono_modal="+telephone_modal+,
- dataType: "html",
- success: function(msg)
- {
- $("#result_insert").html(msg);
- },
- error: function()
- {
- alert("Chiamata fallita, si prega di riprovare...");
- }
- });
- });
-
- });
this is the modal:
- <div id="ClientiModal" class="modal fade">
- <div class="modal-dialog">
- <div class="modal-content">
- <div class="modal-header">
- <button class="close" data-dismiss="modal">×</button>
- <h4 class="modal-title">Inserimento clienti</h4>
- </div>
- <div class="modal-body-insert">
- <form class="form-horizontal" role="form">
- <!-- Form Modale -->
- <div class='form-group'>
- <label class=' col-sm-2 control-label'>Nome*</label>
- <div class=' col-sm-10'>
- <input class='form-control' type='text' id='id_class_nome_modal' name='nome' maxlength='100' >
- </div>
- </div>
- <div class='form-group'>
- <label class=' col-sm-2 control-label'>Cognome*</label>
- <div class=' col-sm-10'>
- <input class='form-control' type='text' id='id_class_cognome_modal' name='cognome' maxlength='100' >
- </div>
- </div>
- <div class='form-group'>
- <label class=' col-sm-2 control-label'>Telefono*</label>
- <div class='col-sm-10'>
- <input class='form-control' type='text' id='id_class_telefono_modal' name='telefono' maxlength='15' >
- </div>
- </div>
- </div>
- <span>note: * campi obbligatori</span>
- <div class='text-center'>
- <button class="btn btn-danger" data-dismiss="modal">
- Annulla</button>
- <button class='btn btn-info' type='button' id='button_insert_cliente' >INSERISCI</button>
- </div>
- <br>
-
- <div class='col-sm-12' id='result_insert'>
-
- </div>
-
-
- </form>
-
-
-
- <!-- /*Form Modale -->
- </div>
- <div class="modal-footer">
- <button class="btn btn-default" data-dismiss="modal">
- Chiudi</button>
- </div>
- </div><!-- /.modal-content -->
- </div><!-- /.modal-dialog -->
- </div><!-- /.modal -->
-
In php i have a function to save data in db , the funztion control if name,surname and telephone aren't empty and save data in db .
If empty show an error message else show a success message.
The problem is if the field are not empty and click on insert button for more than one time , a duplicte record is saved on db .
Ho can i reset and close modal only if the message is a success message (or if a variable setting by the php code to 1 on empty errors)?