CodeIgniter Forums

Full Version: passing variables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I have a question that probably has a simple answer but I cannot find it in the doc.

Here is the sample code from the Form Validation tuturial
class Form extends Controller {
    function index()
        $this->load->helper(array('form', 'url'));

        $this->form_validation->set_rules('username', 'Username', 'required');
        $this->form_validation->set_rules('password', 'Password', 'required');
        $this->form_validation->set_rules('passconf', 'Password Confirmation', 'required');
        $this->form_validation->set_rules('email', 'Email', 'required');

        if ($this->form_validation->run() == FALSE)
I want to pass the username and email that were submitted to the formsuccess view and display them, so I added the following lines to the code before the line that passes control to the formsuccess view:
$data['username'] = 'username';
$data['email'] = 'email';
And I set up the proper code in formsuccess.php to display the data.
Naturally, it just displays 'username' and 'email' instead of what the user (me) entered.
I have tried several different ways, such as $username, username without the quotes, etc.

What do I need to put in place of 'username' and 'email' to do what I want to do?

El Forum

Hi Briggl, you need to pass the posted variables.
Read the input class documentation in

$data['username'] = $this->input->post('input_name');
$data['password'] = $this->input->post('input_name');

Change input_name with the correct values.

El Forum

Thanks, JonyR

I got it to work by using

$data['username'] = set_value('username')
$data['email'] = set_value('email')

But now I have a follow-on question.

By doing this I can pass the information to the next view, formsuccess.
How do I create a global variable so that I can pass the information on to other views after that?

El Forum

I have resolved this by using session data.