Php 如果使用codeigniter提交表单,则保持输入值不变
这是我的登录表单:Php 如果使用codeigniter提交表单,则保持输入值不变,php,html,codeigniter,Php,Html,Codeigniter,这是我的登录表单: <div class="form-container"> <h1 style="text-align:left">Login Here!</h1><br> <form class="form-horizontal" action="<?php echo base_url(); ?>index.php/User_Authentication_Controller/logi
<div class="form-container">
<h1 style="text-align:left">Login Here!</h1><br>
<form class="form-horizontal" action="<?php echo base_url(); ?>index.php/User_Authentication_Controller/login_user" method="POST">
<div class="error_msg1"></div>
<input autofocus="autofocus" type="text" name="txt_login_username" class="form-control" placeholder="Username.."/><div class="error_msg2"></div>
<input type="password" name="txt_login_password" class="form-control" placeholder="Password.." /><div class="error_msg3"></div>
<center><button class="btn btn-info" type="submit">Login</button><br/><br/>
<a href="<?php echo base_url();?>index.php/Pages_Controller/show_forgotpassword">Forgot Password?</a></center>
</form>
</div>
这确实有效
现在我的问题是:
正如您在else if($result[“0”][“Status”]==0){}
中所看到的,我所希望的是,在提交页面后,它将重定向回登录,我希望
<div class="error_msg1"></div>
将显示一个错误,告知“您的帐户已被管理员停用”,如果他输入用户名,在提交时将保持静止!我该怎么做?如果他输入用户名:Michael并输入了错误的密码,我希望用户名:Michael保持静止!提交表单后,我将如何执行此操作?方式1
使用AJAX
而不是form
。js向服务器发送ajax帖子,然后获得结果。根据具体情况,js会做出反应,例如,显示错误消息。这是一个很好的选择
方式2
例如,您可以在login\u user中设置$\u SESSION['ShowErrorMsg1']=true
,然后在您的登录页面php中,只需说:
if(isset($\u会话['ShowErrorMsg1'])和&$\u会话['ShowErrorMsg1']==true){
回声';
}
然后将显示错误消息
更新:
其主要思想是,您可以在
$\u SESSION
中存储任何您想从一个php传递到另一个php的内容。例如,如果您想传递$msg\u内容
,只需使用$\u会话['somekey']=$msg\u内容代码>在一个php中。然后在另一个php中使用$\u会话['somekey']
谁存储$msg\u内容的数据
您可以使用set\u userdata存储错误消息,并可以显示:
在控制器中:
public function login_user(){
$username = $this->input->post('txt_login_username');
$password = md5($this->input->post('txt_login_password'));
$result=$this->LogIn_Model->login($username,$password);
if (!empty($username) && !empty($password)) {
if($result!=null){
$_SESSION["username"] = $username;
$_SESSION["id"] = $result["0"]["Account_no"];
$_SESSION["Usertype"] = $result["0"]["Usertype"];
if($result["0"]["Status"] == 1){
if($result["0"]["Usertype"] == 0){
redirect('User_Authentication_Controller');
}
else if($result["0"]["Usertype"] == 1){
redirect('Pages_Controller/show_adminpage/');
}
}
else if($result["0"]["Status"] == 0){
redirect('User_Authentication_Controller');
}
}
else{
redirect('User_Authentication_Controller');
}
}
else{
redirect('User_Authentication_Controller');
}
}
else if($result["0"]["Status"] == 0){
$this->session->set_flashdata('error_msg1','Some Error Msg!');
}
在你看来:
<?php if($this->session->flashdata('error_msg1')) : ?>
<div class="alert alert-success">
<span class="alert-rr">
<i class="fa fa-check-circle" aria-hidden="true"></i>
</span>
<span class="alert-msg">
<?php echo $this->session->flashdata('error_msg1'); ?>
</span>
</div>
<?php endif; ?>
我喜欢另一种方式,因为我还不知道如何使用AJax!但我的问题是如何得到错误信息?bcoz它在类中,如果我将类更改为name,我仍然无法获得值bcoz类型不是输入,而是div!我将如何把它放在登录用户中?谢谢伙计!现在我真的明白了$_会话是非常有用的人!非常感谢你!
<?php if($this->session->flashdata('error_msg1')) : ?>
<div class="alert alert-success">
<span class="alert-rr">
<i class="fa fa-check-circle" aria-hidden="true"></i>
</span>
<span class="alert-msg">
<?php echo $this->session->flashdata('error_msg1'); ?>
</span>
</div>
<?php endif; ?>