[eluser]Unknown[/eluser]
Hi everyone,
I am starting out with CI and just writing a simple login page.
On my main page I have a form with elements like:
Code:
<tr>
<td><?=form_label('First Name:','u_fname');?></td>
<td><?=form_input('u_fname',$u_fname);?></td>
</tr>
So if the customer hits submit but has an error his data will still be in the form when he is returned.
My current Setup:
In the constructor I set each value i will pass to the View page to nothing:
Code:
$this->data['u_fname'] = '';
Because if the View is loaded but
a value isn't set you get a warning.
I read in the $_POST data to my $user_array so I can add the user,
but I put it in a separate array from my data array so i'm not sending
the entire thing to my add_user class method.
Code:
$user_array['u_fname'] = $this->input->post('u_fname');
If he fails I need to send my data array back to my View page like:
Code:
$this->load->view('welcome_message',$this->data);
So basically my overhead is having to do something like:
Code:
$this->data = array_merge((array)$this->data, (array)$user_array);
So I can use the post_data in my method, and for my View page display.
Is there a better way ? LIke
Code:
$this->load->view('welcome_message',$this->data,$user_array);
the
$this->data part is just because I made $data a class variable instead of in
the method so I could set all the array parts to '' (nothing) from my constructor to avoid variable undefined warnings.
Hope I explained that well enough. If you have questions please ask. I'm interested to see how it should be done.