Using POST data after verification with CodeIgniter

I have a registration form where I check user input. Here is my controller:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Register extends CI_Controller {

    public function index()
    {
        $this->load->model('Users_model');
        $this->load->helper('form');
        $this->load->library('form_validation');

        $data['page_title'] = 'Register';
        $this->load->view('header', $data);

        // Set form validation rules
        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[16]|xss_clean|callback_username_check');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|min_length[5]|max_length[64]|valid_email|callback_email_check');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_error_delimiters('<span class="error">', '</span>');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('register', $data);
        }
        else
        {
            // Add the user to the database
            $this->Users_model->add_user();
            $this->load->view('register_success', $data);
        }

        $this->load->view('footer', $data);
    }

    /* Functions to check username and email */
}

/* End of file register.php */
/* Location: ./application/controllers/register.php */

The problem is this line: $this->Users_model->add_user();. I want to pass the username, email address and password of the user model to add the user to my database, but I'm not sure how I can get the POST data in this method. Usually I used $_POST['username']etc., but CodeIgniter ran some functions on input values ​​( trim(), xss_cleanetc.). How can I get these values ​​and pass them to my method add_user()?

+5
source share
3 answers

CodeIgniter POST , . :

$username = $this->input->post('username');
$email = $this->input->post('email');
$password = $this->input->post('password');
+14

,

+1

You can use an input class as well as a helper function set_value('email')

0
source

All Articles