Welcome Guest, Not a member yet? Register   Sign In
Registration validation includes field from other form
#1

[eluser]Patrick Reck[/eluser]
I am trying to validate a registration form on my page using the built-in CI form validation. However, it is trying to validate my login fields as well when submitting the registration form!

The bottom 2 validation errors on the attached image is from the login form.

Here goes the code:
Login controller method (this is the rules it includes in my other form):

Code:
public function login() {
        $this->form_validation->set_rules('email_adress', 'Email Adress', 'required|valid_email');
        $this->form_validation->set_rules('password', 'Password', 'required|min_length[4]');

        if ($this->form_validation->run() !== FALSE) {
            // Passed
            $this->load->model('user_model');
            $result = $this->user_model->verifyUser();

            if ($result !== FALSE) {
                $this->session->set_userdata('userid', $result->id);
                redirect('');
            }
        }

Login view:

Code:
echo form_open('user/login');
echo form_input('email_adress', 'E-mail adresse', 'class="input_login"');
echo form_password('password', 'Kodeord', 'class="input_login"');  
echo form_submit('login', 'Login', 'class="submit_login"');
echo form_close();

Registration controller method:

Code:
public function activate($activation_key) {
        $this->load->model('user_model');
        $data['user'] = $this->user_model->getUserByActivationKey($activation_key);

        $this->form_validation->set_rules('activate_first_name', 'Fornavn', 'required|min_length[2]');
        $this->form_validation->set_rules('activate_last_name', 'Efternavn', 'required|min_length[2]');
        $this->form_validation->set_rules('activate_password', 'Kodeord', 'required|min_length[6]|matches[password_confirmation]');
        $this->form_validation->set_rules('activate_password_confirmation', 'Kodeord igen', 'required|min_length[6]');
        
        if ($data['user']->activated == 0) {
            $data['module'] = "user";
            $data['view'] = "user_activate_view";
            $data['activation_key'] = $activation_key;
            $data['email_adress'] = $data['user']->email_adress;

            echo Modules::run('template', $data);
        } else {
            $data['module'] = "template";
            $data['view'] = "error_view";
            $data['error'] = "User is already activated";

            echo Modules::run('template', $data);
        }
    }

Registration view:

Code:
<?php
echo form_open('user/activate/'.$activation_key);
?>
<table>
    <tr>
        <td>E-mail:</td>
        <td>&lt;?php //echo form_input('', $email_adress, 'disabled="disabled"'); ?&gt;</td>
    </tr>
    <tr>
        <td>Fornavn: </td>
        <td>&lt;?php echo form_input('activate_first_name', set_value('first_name')); ?&gt;</td>
    </tr>
    <tr>
        <td>Efternavn: </td>
        <td>&lt;?php echo form_input('activate_last_name', set_value('last_name')); ?&gt;</td>
    </tr>
    <tr>
        <td>Kodeord: </td>
        <td>&lt;?php echo form_password('activate_password'); ?&gt;</td>
    </tr>
    <tr>
        <td>Kodeord igen: </td>
        <td>&lt;?php echo form_password('activate_password_confirmation'); ?&gt;</td>
    </tr>
    <tr>
        <td></td>
        <td>&lt;?php echo form_submit('activate_user', 'Registrer bruger');?&gt;</td>
    </tr>
</table>
&lt;?php
echo form_close();
echo validation_errors();
?&gt;

I hope someone already knows this problem or can spot it, because I can't!




Theme © iAndrew 2016 - Forum software by © MyBB