Welcome Guest, Not a member yet? Register   Sign In
Help with overhead
#1

[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>&lt;?=form_label('First Name:','u_fname');?&gt;</td>
            <td>&lt;?=form_input('u_fname',$u_fname);?&gt;</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.
#2

[eluser]Dennis Rasmussen[/eluser]
Do you know of the form_helper function set_value('field_name', 'default_value'); ?
Otherwise you can also set a default value as the second parameter in $this->input->post('u_frame', 'default_value_if_field_isnt_set');

I hope I didn't misunderstand what you were trying to say Smile
#3

[eluser]Unknown[/eluser]
Ah, yes I think thats exactly the answer I was looking for.
I kept thinking I had to send every value i want to output from the control.

apparently set_value also handles htmlspecialchar's like "

Thanks !




Theme © iAndrew 2016 - Forum software by © MyBB