0

我在 CodeIgniter 的网站上的 ONE 视图中有一个登录表单和一个创建成员表单。

问题是,当我提交错误的表单时(在登录表单上按密码和电子邮件的空字段提交),它会触发创建成员表单中的电子邮件和密码字段,反之亦然。

我给了他们不同的提交按钮名称,但仍然无法将它们分开。

我已经尝试重命名字段,但是我对要重命名哪些值感到困惑,因为我必须将特定值提交到我的数据库。

这是创建成员表单和控制器:

<?php

            echo form_open('auth/create_member');

            echo form_label('',  'email', array('type'=>'text'));
            $data = array( 'name' => 'first_name', 'class' => 'input', 'placeholder' => 'First Name' );
            echo form_input($data, set_value('first_name'));
            echo "<span class='errors'>";
            echo form_error('first_name');
            echo "</span>";

            echo form_label('',  'last_name', array('type'=>'text'));
            $data = array( 'name' => 'last_name', 'class' => 'input', 'placeholder' => 'Last Name' );
            echo form_input($data, set_value('last_name'));
            echo "<span class='errors'>";
            echo form_error('last_name');
            echo "</span>";

            echo form_label('',  'email', array('type'=>'text'));
            $data = array( 'name' => 'email', 'class' => 'input', 'placeholder' => 'Email' );
            echo form_input($data, set_value('email'));
            echo "<span class='errors'>";
            echo form_error('email');
            echo "</span>";

            echo form_label('',  'password', array('type'=>'password'));
            $data = array( 'name' => 'password', 'class' => 'password', 'size' => 30, 'placeholder' => 'Password'  );
            echo form_password($data, set_value('sha1(password)'));
            echo "<span class='errors'>";
            echo form_error('password');
            echo "</span";

            echo form_label('',  'password2', array('type'=>'password'));
            $data = array( 'name' => 'password2', 'class' => 'input', 'size' => 30, 'placeholder' => 'Confirm Password'  );
            echo form_password($data, set_value('sha1(password2)'));
            echo "<span class='errors'>";
            echo form_error('password2');
            echo "</span>";

            echo form_submit('submit', 'Submit');
            echo form_close();
            ?>

function create_member() 
    {
        $this->load->library('form_validation');
        $this->form_validation->set_rules('first_name', 'First Name', 'trim|required');
        $this->form_validation->set_rules('last_name', 'Last Name', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]');
        $this->form_validation->set_rules('password', 'Password', 'trim|required'); 
        $this->form_validation->set_rules('password2', 'Confirm Password', 'trim|required|matches[password]');

        if($this->form_validation->run() == FALSE)
        {
            $data['main_content'] = 'home/home_page';
            $this->load->view('includes/templates/home_page_template', $data);
        }
        else 
        {
            $this->load->model('user_model');
            if($query = $this->user_model->create_member())
            {
                $this->load->model('user_model');
                $this->varification_email();
                $data['main_content'] = 'account/welcome';
                $this->load->view('includes/templates/main_page_template', $data);

            }
            else
            {
                $this->load->view('home/home_page');
            }
        }
    }

这是登录表单和控制器:

<?php

                echo form_open('auth/validate_credentials_login');

                echo "<span class='errors_login'>";
                echo form_error('email');
                echo "</span>";

                echo form_label('',  'email',  array('type'=>'text'));
                $data = array( 'name' => 'email', 'class' => 'input', 'placeholder' => 'Email');
                echo form_input($data, set_value('email'));


                echo "<span class='errors_login'>";
                echo form_error('password');
                echo "</span>";

                echo form_label('',  'password', array('type'=>'password'));
                $data = array( 'name' => 'password', 'class' => 'input', 'placeholder' => 'Password');
                echo form_password($data, set_value('sha1(password)'));

                echo form_submit('submit_login', 'Login');
                echo form_close();

                ?>      

function validate_credentials_login()
   {
        // WHEN THE VIEW IS LOADED THIS FUNCTION IS CALLED AND LOADS MODEL AS WELL AS DEFINES THE SALT VARIABLE AND LOADS THE ENCRYPTING HELPER LIBRARY

        $this->load->library('encrypt');
        $this->load->helper('url');
        $this->load->library('form_validation');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'trim|required');
        $this->load->library('session');
        $this->load->model('user_model', 'um');
        $login = $this->input->post('submit_login');





   if($login) {
                $user = $this->um->validate_home_login(array('email' => $this->input->post('email')));
                if( $user ) {

                    // CHECK THE USER'S PASSWORD AGAINST THE ONE FROM THE LOGIN FORM
                    if($user->password == $this->encrypt->sha1( $user->salt . $this->encrypt->sha1($this->input->post('password')))) {
                        $this->session->set_userdata(array(
                            'email' => $this->input->post('email')
                        ));
                        redirect('account/dashboard');
                        exit;
                    }
                }
            }
   }
4

1 回答 1

2

首先,您只是if块内的所有验证规则

这意味着单击提交时..

于 2012-10-04T05:41:47.207 回答