views:

1992

answers:

4

In the controller, I have...

function update($id = null)
{
    $this->load->database();

    // more code

    $data = array();
    $data = $this->db->get_where(
            'users',
            array(
            'id' => $id
            )
        );
    $data = $data->result_array();
    $data = $data[0];

    // more code

    $this->load->view('update', $data);
}

In the view, I have...

<h5>Username</h5>
<input type="text" name="username" value="<?php echo set_value('username'); ?>" size="50" />

<h5>Email</h5>
<input type="text" name="email" value="<?php echo set_value('email'); ?>" size="50" />

<h5>Email Confirmation</h5>
<input type="text" name="emailconf" value="<?php echo set_value('emailconf'); ?>" size="50" />

<h5>Password</h5>
<input type="text" name="password" value="<?php echo set_value('password'); ?>" size="50" />

<h5>Password Confirmation</h5>
<input type="text" name="passconf" value="<?php echo set_value('passconf'); ?>" size="50" />

set_value() isn't reading $data

search for value=""

at http://codeigniter.com/forums/viewthread/103837/

The poster uses only the set_value() function between "" in value="".

I'm wondering how to do the same, but I can't get it to work. Help?

+3  A: 

Hi,

I think you not passing the value correct to the view.

In the Controller put

$data = $this->db->get_where(
        'users',
        array(
        'id' => $id
        )
    );
$data = $data->result_array();

$data['result'] = $data[0];

then in the view example:

<h5>Password Confirmation</h5> <input type="text" name="passconf" value="<?php echo result['passconf']; ?>" size="50" />

Regards, Pedro

Pedro
+1  A: 

Hi,

Try this:

Controller:

$data = array();
$data = $this->db->get_where(
        'users',
        array(
        'id' => $id
        )
    );
$data = $data->result_array();
$data['view_username'] = $data['username'];

Instead of using $date[0], I use the column name, but that's your decision

View:

<h5>Username</h5> <input type="text" name="username" value="<?=$view_username?>" size="50"/>

<?= => is PHP short tag, read about it in the codeigniter user guide

Regards,

Sylvio

Sylvio
A: 

set_value requires 2 parameters. field name AND value.

You need:

value="<?php echo set_value('username', $username); ?>"

assuming that you are passing $data['username'] etc.

esryl
A: 

Hi pals, Your solutions not Working in my case, I believe it is a bug in CI need to fix, my case is really simple I don't get the repopulated data in a text box after validation error. That data got for the fields involved in validation but not in other fields. If any Body got a solution pls inform me

Regards Anes P.A

Anes