Keeping the entered value at, whether the form is submitted using codeigniter
This is my login form:
<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>
This is my controller:
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');
}
}
It really works!
Now my question is:
As you can see else if($result["0"]["Status"] == 0){}, all I want is that after I submit the page, it will redirect back to the login, and I want
<div class="error_msg1"></div>
will display an error message: "Your account has been deactivated by the administrator." And if he enters the username, he will remain motionless when he introduces him! how will i do this If he enters the username: Michael and Inputs the wrong password, I want the username: Michael to stay in place! How to do this after submitting the form?
1
AJAX form. js ajax , . js , , . .
2
, $_SESSION['ShowErrorMsg1']=true login_user, php, :
.
if(isset($_SESSION['ShowErrorMsg1']) && $_SESSION['ShowErrorMsg1']==true){
echo '<div class="error_msg1"></div>';
}
.
UPDATE:
, , , php php $_SESSION. $msg_content, , $_SESSION['somekey']=$msg_content; php. php $_SESSION['somekey'], $msg_content.
set_userdata : :
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; ?>