passing data from one controller function to another

#1
[eluser]newtonianb[/eluser]
I have an index function that loads a view with a form, this index function handles the validation of this form. If the validation succeeds I want the data to be passed along to complete a second form.

The way I currently have this setup is:

My index page is a form with form validation, if the validation succeeds the data of this form is sent to a different function within that same controller through url using redirect and passing data as arguments but my problem here is that i have to redo the validation all over again in the new function (and can't use form helper there).

How else could I send the data? The reason I want this other function to handle it is first its a whole different form of itself and second, I want the user to be able to quickly trigger my function from url.

Any help appreciated, please ask if you need clarification.

#2
[eluser]daelsepara[/eluser]
please post code.

#3
[eluser]newtonianb[/eluser]
I use varone and vartwo to call a function in func2() which retrieves data for options in the func2() form

#4
[eluser]daelsepara[/eluser]
One way to pass it is via session flashdata:

Code:
$this->session->set_flashdata('varone', 'value');
redirect('some_page');

in the next controller:

Code:
function some_page()
{
  $varone = $this->session->flashdata('varone');
}

the data is available only (up to) the next server request.

Otherwise, you would code your controllers in the following manner:

Code:
function func2($varone = "", $vartwo = "")
{
}

where the statements inside func2:

Code:
$varone = "", $vartwo = ""

refers to the default value for these variables should func2 be
called when none are given.

Have I understood your problem correctly?

#5
[eluser]newtonianb[/eluser]
this is great, thanks!
do i need do add some validation to the data as it gets to the new function if it is stored in flash data? Is it easy for someone to tamper the data or is it stored on server.

My ideal situation is if the data is stored on server and never on client so they have no way to temper with it.

#6
[eluser]daelsepara[/eluser]
if you have already validated the data, there is little need for it on redirection to the next controller, perhaps just a check if it's empty or not. Of course, you are still encouraged to do some other checks, after validation (whether the value's relevant to the next controller, but you may do it before passing it).

Also, You can modify your

Code:
$submitone = $this->input->post('varone');
$submittwo = $this->input->post('vartwo');

codes to:

Code:
$submitone = $this->input->post('varone',TRUE);
$submittwo = $this->input->post('vartwo',TRUE);

to pass them through an XSS filter before setting them as flashdata.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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