• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
passing variables

#1
[eluser]briggl[/eluser]
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
Code:
<?php
class Form extends Controller {
    function index()
    {
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');

        $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)
        {
            $this->load->view('myform');
        }
        else
        {
            $this->load->view('formsuccess');
        }
    }
}
?>
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:
Code:
$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?

#2
[eluser]jonyr[/eluser]
Hi Briggl, you need to pass the posted variables.
Read the input class documentation in http://ellislab.com/codeigniter/user-gui...input.html

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

Change input_name with the correct values.

#3
[eluser]briggl[/eluser]
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?
Thanks.

#4
[eluser]briggl[/eluser]
I have resolved this by using session data.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.