Welcome Guest, Not a member yet? Register   Sign In
1.7 Form validation
#1

[eluser]nzmike[/eluser]
Hi there,

I've been building an application for a few months now a decided to upgrade to latest version of Code Igniter (1.7) to try out the new form validation class. I have everything working except for two things.

1. In the old validation class I would use something like:

Code:
$this->validation->content = $result->content;

To populate the inputs with data from the database and this doesn't seem to work with the new validation class (and yes I am changing it to $this->form_validation->content = $result->content).

2. To actually insert/update a value from the form to the database I called the model from the controller with something like:

Code:
$this->example_model->insert_content($this->validation->content)

Is this the correct way of doing it? And how do I do this in the new validation class? I've read the documentation but couldn't find answers to these questions...maybe I'm missing something.

Anyway Cheers,
Mike
#2

[eluser]Thorpe Obazee[/eluser]
I believe you'll need

Code:
$this->example_model->insert_content($this->form_validation->content)

to access the value of the input field. You can also use:

Code:
$this->example_model->insert_content($this->input->post('content'))
#3

[eluser]nzmike[/eluser]
Thanks for the reply.

Using
Code:
$this->input->post('content')
seems to do the trick however if I try and use:
Code:
$this->form_validation->content
instead I get this error:

Message: Undefined property: CI_Form_validation::$email

And still don't understand how you pre-populate fields from a database.

Cheers,
Mike
#4

[eluser]Thorpe Obazee[/eluser]
This is what I do to pre polulate the form field(it's in the user guide).

Code:
<input type="text" class="span-2" value="<?php echo set_value('username');?>" name="username" id="username" />


However, if you have something from the database, you might have something like this where $user->first_name is the default value(from the database)

Code:
<input type="text" value="<?php echo set_value('first_name', $user->first_name);?>" name="first_name" id="first_name" />
#5

[eluser]nzmike[/eluser]
Hmm I couldn't seem to find that in the user guide, maybe I'll take another look.

Thanks for your help,
Mike
#6

[eluser]Thorpe Obazee[/eluser]
Just make sure you're reading the updated one :p




Theme © iAndrew 2016 - Forum software by © MyBB