提交后获取弹出消息

时间:2018-05-28 09:32:56

标签: javascript jquery ajax

表单提交后我没有收到甜蜜的提醒消息,或者有任何方法在表单提交后刷新页面时弹出消息

 <form method="POST"  onSubmit="myFunction()" >
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "FirstName" name="fname" id="fname" required ></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "LastName"name="LNAME" id="LNAME" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "Email"name="email"  id="email" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "phone No."name="PHONE" id="PHONE" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "ADDRESS"name="ADDRESS" id="ADDRESS" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "Existing site"name="MMERGE3" id="MMERGE3" required></div>
  <div class="col-md-12"><textarea cols="" rows="" name="INSTR" id="INSTR"></textarea></div>


  <div class="col-md-12"><button type="submit" type ="hidden" value="send">Create my new website now</button></div>
</form>

<script>


function myFunction() {
    swal(
'Awesome !',
'Form Submitted Successfully!',
'success'
);
}
</script>

3 个答案:

答案 0 :(得分:1)

 <form method="POST" name="myform" id="myform" action="index.php"> 
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "FirstName" name="fname" id="fname" required ></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "LastName"name="LNAME" id="LNAME" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "Email"name="email"  id="email" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "phone No."name="PHONE" id="PHONE" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "ADDRESS"name="ADDRESS" id="ADDRESS" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "Existing site"name="MMERGE3" id="MMERGE3" required></div>
  <div class="col-md-12"><textarea cols="" rows="" name="INSTR" id="INSTR"></textarea></div>


  <div class="col-md-12"><button type="submit" type ="hidden" value="send">Create my new website now</button></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">&times;</span></button>
        <h4 class="modal-title text-center">We Will contact you soon</h4>
      </div>
      <!--<div class="modal-body">

      </div> -->
      <div class="modal-footer">
        <button type="button" class="btn green-btn" data-dismiss="modal" onClick="$('#myform').unbind().submit();">ok</button>
      </div>
    </div>
  </div>
</div>
<script>
$(document).ready(function(){

 $("#myform").submit(function(e) { 
 e.preventDefault();
 $('#myModal').modal({backdrop: 'static', keyboard: false});


return true; 
    });


});

function myFunction() {
    $('#myModal').modal('show');
//alert('We Will contact you soon!!!');

}
</script>

答案 1 :(得分:0)

在提交端包含您的甜蜜提醒功能或在

内提交表单成功

&#13;
&#13;
function submits(){
 //stuff here
 
 //include your sweet alert function inside the submit end or submit form success inside
  swal(
'Awesome !',
'Form Submitted Successfully!',
'success'
);

 false;
}
&#13;
<form onsubmit="return submits()">
<input>
</form>
&#13;
&#13;
&#13;

答案 2 :(得分:0)

<form method="POST"  onSubmit="myFunction()" >
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "FirstName" name="fname" id="fname" required ></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "LastName"name="LNAME" id="LNAME" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "Email"name="email"  id="email" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "phone No."name="PHONE" id="PHONE" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "ADDRESS"name="ADDRESS" id="ADDRESS" required></div>
  <div class="col-md-6"><input type="text" class="validate-required" placeholder = "Existing site"name="MMERGE3" id="MMERGE3" required></div>
  <div class="col-md-12"><textarea cols="" rows="" name="INSTR" id="INSTR"></textarea></div>


  <div class="col-md-12"><button type="submit" type ="hidden" value="send">Create my new website now</button></div>
</form>

<script>


function myFunction(event) {
    event.preventDefault();
    $.ajax({
      data:'your_form_data',
      dataType: 'json',
     url: 'your_ajax_url',
      success:function(data){
       your pop up call
    }
    })

}
</script>