弹出窗口中显示错误消息

时间:2018-01-03 12:51:13

标签: php codeigniter

我在主页上显示弹出登录表单。当我弹出错误的电子邮件/密码弹出时,弹出弹出窗口弹出错误信息。

我的主页

           <div class="modal fade" id="signin" role="dialog">
<div class="modal-dialog ">   
  <div class="modal-content"> 

    <div class="modal-header"> 
      <button type="button" class="close" data-dismiss="modal">&times;</button>
      <h4 class="modal-title"> Sign in </h4>
    </div>
    <div class="modal-body">  
        <div class="tabiib-popbox">
         <div class="col-xs-12"> 

      <ul class="nav nav-tabs poptabs">

        <li class="tab signin"><a data-toggle="tab" href="#home"> Sign In</a></li>

      </ul>
     <div class="tabiib-signin">
     <div class="tab-content">
     <div id="home" class="tab-pane fade in">
          <form class="pop-l" action="<?php echo base_url('LoginPopup');?>"    method="post" name="signin" enctype="multipart/form-data">
       <?php echo $this->session->flashdata('Message');?>
      <div class="form-group">
        <label for="email">Mobile Number / Email ID </label>
        <input type="text" name="emailMobileNumber" class="form-control" id="email">
      </div>

      <div class="form-group">   
        <label for="pwd">Password</label>
        <input type="password" name="password" class="form-control" id="pwd">
      </div>


      <div class="pop-b text-center"> 
      <input type="submit" class="btn popbtn" value="Sign In">        
       </div>   
    </form> 
</div>

控制器:

       public function    LoginPopup() {        

        $postDatas = $this->input->post();

        $postData = str_replace (" ", "", $postDatas);
        $postData['userType'] = 3;
        $this->load->model('modelname');
        $response = $this->modelname->login($postData);

        if(isset($response['success_message'])) {

            $user = set_user_session($response['data']);
            $this->session->set_userdata('userdata', $user);
            $sessionData = $this->session->userdata('userdata');
            $this->session->set_userdata('Login',1);
            $details = getDet($sessionData['userRef']);
            $this->session->set_userdata('Details', $details);

            redirect('');  
            }else{

            $msg = '<div class="alert alert-danger"><i class="fa fa-ban"></i>';
            $msg .= 'Mobile Number/Email or Password does not match';
            $msg .= '</div>';
            $mesg=$this->session->set_flashdata('Message', $msg);           

        redirect('');   

            }
    }

但是我需要弹出窗口会在弹出窗口中显示错误信息,直到我们给出正确的电子邮件/密码弹出窗口不会隐藏

3 个答案:

答案 0 :(得分:0)

最好的方法是,使用ajax提交表单。但是如果你不想在最初使用ajax,那么如果出现错误,请在会话中写入错误消息。然后在主页中重定向后,检查会话是否有错误。如果有错误,则显示模型并显示错误消息。但它不是一个闪存消息记住它。

答案 1 :(得分:0)

试试这个

替换

def option_a():
    fixchoice = int(input("Enter: "))

    file = open("firesideFixtures.txt", "r")
    print(file.readlines(fixchoice))

option_a()

$msg = '<div class="alert alert-danger"><i class="fa fa-ban"></i>';
$msg .= 'Mobile Number/Email or Password does not match';
$msg .= '</div>';
$mesg=$this->session->set_flashdata('Message', $msg);           
redirect('');   

在LoginView中添加一些行

$data['msg'] = '<div class="alert alert-danger"><i class="fa fa-ban"></i>';
$data['msg'] .= 'Mobile Number/Email or Password does not match';
$data['msg'] .= '</div>';
$this->load->view('LoginView',$data); #LoginView  is a view where you login form is present

答案 2 :(得分:-1)

如果您使用重定向(''),那么肯定会重定向页面并且不会显示弹出窗口。使用ajax表单提交它将解决您的问题。