在codeigniter中显示忘记密码的成功消息

时间:2016-09-05 11:53:12

标签: php codeigniter

我创建了忘记密码模块。

我的问题:在忘记密码模块中输入电子邮件地址,然后单击发送按钮,然后在同一页面中显示消息。

控制器:

class User extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->driver('cache');
        $this->load->library('form_validation');
        $this->load->model('user_model');
        $this->load->library('session');
    }
 public function forgotpassword() {
        $this->form_validation->set_rules('email', 'Email Address', 'required|valid_emails|callback_errormsg', array('errormsg' => 'Invalid Email Address'));
        if ($this->form_validation->run() == FALSE) {
            $data = array(
                'page_title' => 'Forgot Password',
                'page_name' => 'user/forgotpassword'
            );
            $this->load->view('user_template', $data);
        } else {
            $this->form_validation->set_message('success', 'Check Email');
        }
    }
    public function errormsg() {
        $result = $this->user_model->forgotpassword($_POST);
        if (!empty($result)) {
            $token = sha1(microtime());
            $this->user_model->updatetoken($token, $result['user_id']);
            $email = base64_encode($result['email']);
            $message['link'] = anchor(base_url("User/resetpassword/{$email}/{$token}"), ' Rest Password');
            echo 'Check Email';
        return TRUE;
    } else {
        return FALSE;
    }
}
}

查看:

<section class="container">
    <section class="login-form">
        <?php echo form_open('User/forgotpassword', array('role' => 'login')); ?>
        <h2>Forgot Password</h2>
        <ul class="text-danger">
            <?php echo validation_errors('<li>', '</li>'); ?>
        </ul>
        <input type="text" name="email" id="email" class="form-control" placeholder="Enter Email Address"  value="<?php echo set_value('email'); ?>" required=""/>
        <button type="submit" name="submit" class="btn btn-block btn-primary">Send</button>
        <?php echo form_close(); ?>
    </section>
</section>

1 个答案:

答案 0 :(得分:0)

Try with this ,



public function forgotpassword() {
        $this->form_validation->set_rules('email', 'Email Address', 'required|valid_emails|callback_errormsg', array('errormsg' => 'Invalid Email Address'));
        if ($this->form_validation->run() == FALSE) {
            $data = array(
                'page_title' => 'Forgot Password',
                'page_name' => 'user/forgotpassword'
            );
            $this->load->view('user_template', $data);
            $this->theme->set_message("Your error message", 'danger');
        } else {
            $this->theme->set_message("Your Success message", 'success');
        }
    }

将以下函数放在application - library - theme.php中,以便在所有模块中使用此函数。

public function set_message($message = '', $type = 'info')
    {
        if (!empty($message))
        {
            if (isset($this->_ci->session))
            {
                $this->_ci->session->set_flashdata('message', $type . '::' . $message);
            }

            $this->message = array('type' => $type, 'message' => $message);
        }
    }