Welcome Guest, Not a member yet? Register   Sign In
Form Validation - Associating a Controller Function with a Rule Group doesn't work
#1

[eluser]oplan[/eluser]
Hi'm pretty new to CI and i'm pretty impressed Smile Full respect to all involved !
Right now i'm trying to follow tutorial: http://ellislab.com/codeigniter/user-gui...ngtoconfig everything worked fine untill i've tried to associate a controller function with a rule group placed in my config/form_validation.php file

my controller:
Code:
<?php

class User extends Controller {

    function User()
    {
        parent::Controller();
        $this->load->helper(array('form', 'url'));    
        $this->load->library('form_validation');
        $this->load->model('User_model');
    }
    function index()
    {
        $this->load->view('_head');
        $data['row'] = $this->User_model->get_users();
        $this->load->view('user_view', $data);
        $this->load->view('_foot');
    }
    function add()
    {
        $this->load->view('_head');
        $data['user_type'] = $this->User_model->get_user_type_list();
        $this->load->view('user_add_view', $data);
        $this->load->view('_foot');
    }
    
    function insert()
    {
        if ($this->form_validation->run() == FALSE)
        {
            add();
        }
        else
        {
            $this->User_model->insert_user();
            redirect('user');
        }
    }

    function delete($id)
    {
        $this->User_model->remove_user($id);
        redirect('user');
    }
    
}

?>
model:

Code:
<?php

class User_model extends Model {

    var $name            = '';
    var $login            = '';
    var $user_type_id            = '';
    var $password        = '';
    var $email                = '';

    function User_model()
    {
        parent::Model();
    }
    
    function get_user_type_list()
    {
        $this->db->select('id, description');
        $query = $this->db->get('user_type');
        $result = array();
        foreach ($query->result() as $row)
        {
            $result[$row->id] = $row->description;
        }
        return $result;
    }

    function insert_user()
    {
        $this->id                = '';
        $this->name                = $_POST['name'];
        $this->login            = $_POST['login'];
        $this->password            = $_POST['password'];
        $this->email            = $_POST['email'];
        $this->user_type_id        = $_POST['user_type_id'];
         $this->user_active        = $_POST['user_active'];
        
        $this->db->insert('user', $this);
    }


    function remove_user($id)
    {
        $query = $this->db->get_where('user', array('id' => $id));
        $this->db->delete('user', array('id' => $id));
    }
}

?>

and my form_validation config file:
Code:
$config = array(
           'user/insert' => array(
                                    array(
                                            'field' => 'login',
                                            'label' => 'Login',
                                            'rules' => 'required'
                                         ),
                                    array(
                                            'field' => 'password',
                                            'label' => 'Password',
                                            'rules' => 'required'
                                         ),
                                    array(
                                            'field' => 'passconf',
                                            'label' => 'Password Confirmation',
                                            'rules' => 'required'
                                         ),
                                    array(
                                            'field' => 'email',
                                            'label' => 'Email',
                                            'rules' => 'required'
                                         )
                                    )
               );

i can't see what's wrong :down:
can anybody help?
thanka a lot
#2

[eluser]danmontgomery[/eluser]
What's the error you're getting?
#3

[eluser]oplan[/eluser]
no error, after submitting form with incorrect data just blank page appears
#4

[eluser]Kamarg[/eluser]
I believe the issue is that your function is called insert_user but in your config you're calling it just insert. Try making it user/insert_user in the config file.
#5

[eluser]oplan[/eluser]
no, blank page neither Sad
#6

[eluser]oplan[/eluser]
is there some debug funcionality i can turn on to see what's posted or somethin like that?
#7

[eluser]Kamarg[/eluser]
I seem to have missed your post saying you were getting a blank page. That sounds like you have an issue that's separate from the form validation. In your main index.php file, try turning error reporting to E_ALL and see if you get any error messages.
#8

[eluser]oplan[/eluser]
it is set to E_ALL
#9

[eluser]danmontgomery[/eluser]
Code:
if ($this->form_validation->run() == FALSE) {
    add();
}

Just guessing that is because the only output you're trying to generate is an undefined function. This should be:

Code:
if ($this->form_validation->run() == FALSE) {
    $this->add();
}
#10

[eluser]oplan[/eluser]
YES! now it's workin Smile thanks a lot noctrum




Theme © iAndrew 2016 - Forum software by © MyBB