Bootstrap 通过 javascript 提交表单时的成功提醒
Bootstrap success alert upon form submition via javascript
我已经在互联网上搜索了几个小时,试图了解如何在用户提交表单时使可关闭的绿色警报向下滑动(非模态)。我认为它与表单验证有关但不确定。请帮忙。
代码无效,因为当我点击表单上的提交时,没有任何反应。验证不适用于表单。 (表单操作属性已留空。)method="post"
我正在使用服务器提供的表单处理脚本(不确定这是否有影响。)
所以我的问题是:如何 "link" 提交按钮将表单发送到服务器,然后通过 jQuery 显示一个可忽略的成功警报,这将适合 col-md- 4?
发生了什么.. 当您将任何页面 (form.php) 提交到其他页面 (form-submit.php).. 消息通过 URL 传递使用 header 函数到 form.php.. 在 form.php 中使用 get 方法选择消息..
form.php
<?
if($_GET['submitted'])
{?>
<div class="alert alert-success" role="alert">
Form Submitted Successfully
</div>
<?}?>
<form ... action='form-submit.php'>
.
.
</form>
form-submit.php
// All submission query..
// at the end, after performing all necessary actions.. need to come to form.php page.. so we will use header("");
header("location:form.php?submitted=successfully");
这是一种在 Bootstrap 模态中执行此操作的简化方法。我们在这里所做的只是检查表单是否已通过 jQuery 提交,然后以模式显示消息。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div id="messages" class="hide" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<div id="messages_content"></div>
</div>
<form id="form" method="post">
<button class="btn btn-default" type="submit">Submit</button>
</form>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
$('#form').submit(function(e) {
$('#messages').removeClass('hide').addClass('alert alert-success alert-dismissible').slideDown().show();
$('#messages_content').html('<h4>MESSAGE HERE</h4>');
$('#modal').modal('show');
e.preventDefault();
});
</script>
</body>
</html>
我已经在互联网上搜索了几个小时,试图了解如何在用户提交表单时使可关闭的绿色警报向下滑动(非模态)。我认为它与表单验证有关但不确定。请帮忙。
代码无效,因为当我点击表单上的提交时,没有任何反应。验证不适用于表单。 (表单操作属性已留空。)method="post"
我正在使用服务器提供的表单处理脚本(不确定这是否有影响。)
所以我的问题是:如何 "link" 提交按钮将表单发送到服务器,然后通过 jQuery 显示一个可忽略的成功警报,这将适合 col-md- 4?
发生了什么.. 当您将任何页面 (form.php) 提交到其他页面 (form-submit.php).. 消息通过 URL 传递使用 header 函数到 form.php.. 在 form.php 中使用 get 方法选择消息..
form.php
<?
if($_GET['submitted'])
{?>
<div class="alert alert-success" role="alert">
Form Submitted Successfully
</div>
<?}?>
<form ... action='form-submit.php'>
.
.
</form>
form-submit.php
// All submission query..
// at the end, after performing all necessary actions.. need to come to form.php page.. so we will use header("");
header("location:form.php?submitted=successfully");
这是一种在 Bootstrap 模态中执行此操作的简化方法。我们在这里所做的只是检查表单是否已通过 jQuery 提交,然后以模式显示消息。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0">
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<div id="messages" class="hide" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
<div id="messages_content"></div>
</div>
<form id="form" method="post">
<button class="btn btn-default" type="submit">Submit</button>
</form>
</div>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script>
$('#form').submit(function(e) {
$('#messages').removeClass('hide').addClass('alert alert-success alert-dismissible').slideDown().show();
$('#messages_content').html('<h4>MESSAGE HERE</h4>');
$('#modal').modal('show');
e.preventDefault();
});
</script>
</body>
</html>