[英]Implementing modal window after form submit to database and remain on the same page
How can I implement a confirmation modal window after after submitting . 如何在提交后实现确认模式窗口。 I can insert data into database from a PHP form , but the problem is it redirects to another page . 我可以从PHP表单将数据插入数据库,但问题是它重定向到另一个页面。 And the value I have written in form still remain . 我在表格中写的价值仍然存在。 I want to remain on the same page just use an confirmation modal window and the form will be refreshed not the whole page . 我想保持在同一页面只使用确认模式窗口,表格将刷新而不是整个页面。
<form role="form" action="db.php" method="post">
<div class="form-group">
<label for="name">Name</label>
<input type="text" class="form-control" id="name" placeholder="Your Full Name">
</div>
<div class="form-group">
<label for="address">Delivery Address</label>
<input type="text" class="form-control" id="address" placeholder="Address">
</div>
<div class="form-group">
<label for="phone">Phone No</label>
<input type="text" class="form-control" id="phone" placeholder="Phone No">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="exampleInputEmail1">Quantity</label>
<select class="form-control" id="quantity">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
<div class="form-group" >
<label for="exampleInputEmail1">Expected Date</label>
<input id="datepicker" />
</div>
<button type="submit" class="btn btn-default" >Submit</button>
</form>
Post your form via ajax. 通过ajax发布您的表单。 See below 见下文
$( "#formid" ).submit(function( event ) {
event.preventDefault();
$.ajax({
url: 'db.php',
type: 'POST',
data: $('#formid').serialize(),
success: function(response) {
if(response == 'Success') {
$('#model_div_id').html("Success");
$('#model_div_id').modal('show'); //twitter bootstrap modal
},
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.