Php 使用modals登录时出现错误消息
如果登录失败,我需要显示一个对话框。现在我可以在表单中显示错误行,但是我需要使用Php 使用modals登录时出现错误消息,php,login,Php,Login,如果登录失败,我需要显示一个对话框。现在我可以在表单中显示错误行,但是我需要使用modals显示错误消息。 这是我的密码: $sfAuth = new SfAuthenticate(); $sfHelper = new SfHelper(); $user = $_POST['txtUsername']; $pass = $_POST['txtPassword']; $checkUser = $sfAuth->checkUserJobSeeker($user); if($check
modals
显示错误消息。
这是我的密码:
$sfAuth = new SfAuthenticate();
$sfHelper = new SfHelper();
$user = $_POST['txtUsername'];
$pass = $_POST['txtPassword'];
$checkUser = $sfAuth->checkUserJobSeeker($user);
if($checkUser)
{
$login = $sfAuth->loginJobSeeker($user, $pass);
if($login)
{
echo $sfHelper->redirect('forms/jobSeeker/HomeJobSeeker.php');
}else{
echo $sfHelper->redirect('forms/jobSeeker/formLoginJobSeeker.php?err=Invalid Username or Password');
}
}else{
echo $sfHelper->redirect('forms/jobSeeker/formLoginJobSeeker.php?err=Sorry, We Cannot found your Username');
}
我想在重定向到登录表单后显示对话框。
有人能帮我吗?将此代码放在formLoginJobSeeker.php文件中
<?php
if($_GET['err'] == "Sorry, We Cannot found your Username")\
{
echo '<script> alert("Sorry Wrong Username Or Password");</script>'
}
?>
要显示模式对话框,您需要javascript。检查前一个SO问题:)。类似地,我建议检查哪个是javascript库jQuery的扩展
分3个步骤,下面介绍其工作原理:
在页面中包括jQuery和jQueryUI库脚本
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"/></script>
使用jQueryUI显示对话框
<script>
$(document).ready(function() {
$( "#dialog" ).dialog();
});
</script>
$(文档).ready(函数(){
$(“#dialog”).dialog();
});
查看完整的工作示例:看看这把小提琴,它应该可以工作:
关于在用户出错时启动模式窗口,您可以添加一个条件:
<?php if(isset($_GET['err']): ?>
launchWindow('#message');
<?php endif; ?>
如果要显示对话框,则必须使用jquery对话框
将以下代码添加到您的页面
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"/></script>
<div id="dialog" title="Basic dialog" style="display:none">
<p>
<?php if(isset($_GET['err'])) echo $_GET['err'];?>
</p>
</div>
<?php if(isset($_GET['err']){ ?>
<script type="text/javascript">
$(document).ready(function() {
$( "#dialog" ).dialog();
});
</script>
<?php } ?>
解决了?
如果不是,我的解决方案是这样的
重定向到类似的内容(注意#run\u model
):
和JS:
function detectModalParam()
{
var hash = $(location).attr('hash');
if (hash == '#run_modal')
{
YOUT_MODAL_FUNCTION();
};
}
$(document).ready(function()
{
detectModalParam();
}
我怀疑需要一些额外的代码来关闭模式框,然后返回主视图?啊,是的。。现在更新为包含关闭语句。只需单击“关闭”或模式外部即可关闭它
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/themes/base/jquery-ui.css" type="text/css" media="all" />
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"/></script>
<div id="dialog" title="Basic dialog" style="display:none">
<p>
<?php if(isset($_GET['err'])) echo $_GET['err'];?>
</p>
</div>
<?php if(isset($_GET['err']){ ?>
<script type="text/javascript">
$(document).ready(function() {
$( "#dialog" ).dialog();
});
</script>
<?php } ?>
`forms/jobSeeker/formLoginJobSeeker.php?err=YOUR_MESSAGE#run_modal`
function detectModalParam()
{
var hash = $(location).attr('hash');
if (hash == '#run_modal')
{
YOUT_MODAL_FUNCTION();
};
}
$(document).ready(function()
{
detectModalParam();
}