• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
multi page forms and genral form question

[eluser]The Casual Bot[/eluser]
I'm brand new to CI this is my first time working with a framework as normal i work in just PHP

So first was gutted about how much time i wasted in the last 2 year using PHP alone Confusedmirk:

Iv been asked to crate i form set to take personal details over about 8 pages there current ones pass the post data into hidden forms but it this does have problems as when the back button is used the data gets lost and the user sends a half full application.

iv done something similar before using just PHP and the session variables so even when the user pressed the back button it did lose and data

so to my question has anyone got any ideas on how best to code a multi page form and the logic they used (or would use) that would also display the data in the fields when the back button is used ???

and question 2 iv looked in the user guide but can find my answer to this iv turned on xss clean globally do i use the post values form my form or are they stored some where else

Thanks In Advanced :-)

The way I've done this in the past is to process (validate) each step individually, and on success add the data to the session. For each field, use the form helper, like this:

<input type="text" name="first_name" value="<?php echo set_value('first_name', $this->session->userdata('first_name')); ?>" />

So if the page has been posted, but is missing some data or something, this function will display the data that was posted in the field, or if you're going back, it'll display the data from the session.

[eluser]The Casual Bot[/eluser]
Got it i did now i could set send a second value to set_value

i have however had made a change to the session lib but unsure if this is the best way to do it
i wanted to use a multidimensional array to store the form data as per page if you get me

iv added to session lib

function userdataarray($item, $item1)
        return ( ! isset($this->userdata[$item][$item1])) ? FALSE : $this->userdata[$item][$item1];

is this the nest way or do you know a better one

[eluser]The Casual Bot[/eluser]
just tried it and it work perfectively

In that case I would send the session data to the view from the controller, like this:

$data = array('formdata' => $this->session->userdata('formdata'));
$this->load->view('myform', $data);

And then in the view, the input would be this:

<input type="text" name="first_name" value="<?php echo set_value('first_name', $formdata['first_name']); ?>" />

That way you don't need to modify the session class.

[eluser]The Casual Bot[/eluser]
i can get this to work every time the page loads

i get

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: data

Filename: personal/Personal.php

Line Number: 31

the controller looks like this

$data = array('formdata');
            $this->form_validation->set_error_delimiters('<li class="error" >', '</li>');
            $this->load->view('personal/Personal', $data);

and the field is

&lt;input name="name" type="text" id="name" class="element text medium" value="&lt;?php echo set_value('name', $data['name'] ); ?&gt;" maxlength="255"/&gt;

[eluser]The Casual Bot[/eluser]

stupid error

i my controller with


$data = array('formdata');

changed to

$data = array('formdata' => $this->session->userdata('1'));


Just remember to use $formdata['name'] in your set_value() function. You have $data right now, it should be $formdata.

[eluser]The Casual Bot[/eluser]
yeah got it

Thank for your help fella Smile

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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