CodeIgniter Forums
[solved] set_value with form_input - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: [solved] set_value with form_input (/showthread.php?tid=44480)



[solved] set_value with form_input - El Forum - 08-15-2011

[eluser]Bianca Migueis[/eluser]
is it possible to use a set_value within a form_input? how?
I've been trying but I can't make it work. Any thoughts would be appreciated however I DO know the link to the user guide. Smile

I have the following codes
Controller
Code:
public function index()
    {
        $data['loggedin'] = $this->cookie->checkcookie();
        
        $data['username'] = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => set_value('username'),
              'maxlength'   => '24',
              'size'        => '24',
              'style'       => '',
            );
        $data['password'] = array(
              'name'        => 'password',
              'id'          => 'password',
              'value'       => set_value('password'),
              'maxlength'   => '24',
              'size'        => '24',
              'style'       => '',
            );
        $data['password2'] = array(
              'name'        => 'password2',
              'id'          => 'password2',
              'value'       => set_value('password2'),
              'maxlength'   => '24',
              'size'        => '24',
              'style'       => '',
            );
        $data['first'] = array(
              'name'        => 'first',
              'id'          => 'first',
              'value'       => set_value('first'),
              'maxlength'   => '24',
              'size'        => '24',
              'style'       => '',
            );
        $data['middle'] = array(
              'name'        => 'middle',
              'id'          => 'middle',
              'value'       => set_value('middle'),
              'maxlength'   => '24',
              'size'        => '24',
              'style'       => '',
            );
        $data['last'] = array(
              'name'        => 'last',
              'id'          => 'last',
              'value'       => set_value('last'),
              'maxlength'   => '24',
              'size'        => '24',
              'style'       => '',
            );
        $data['email'] = array(
              'name'        => 'email',
              'id'          => 'email',
              'value'       => set_value('email'),
              'maxlength'   => '128',
              'size'        => '50',
              'style'       => '',
            );
        $data['submit'] = array(
              'name'        => 'register',
              'id'          => 'register',
              'value'       => 'Register',
              'maxlength'   => '24',
              'size'        => '24',
              'style'       => '',
            );
        
        if ($this->form_validation->run('register') == FALSE)
        {
            $this->load->view('register_view', $data);
        }
        else
        {
            $this->updateDB($_POST);
        }
        
    }

view
Code:
<?php include "header.php" ?>

<center>
<table border="0">


<tr>
    <td width="300"><h3>Register<h3></td>
</tr>
<tr>
    <td>    
        &lt;?=form_open('register');?&gt;
        
        <font color="red">&lt;?=form_error('username');?&gt;</font>
        Username: &lt;?=form_input($username);?&gt;</br>
        <font color="red">&lt;?=form_error('password');?&gt;</font>
        Password: &lt;?=form_password($password);?&gt;</br>
        <font color="red">&lt;?=form_error('password2');?&gt;</font>
        Confirm password: &lt;?=form_password($password2);?&gt;</br>
        <font color="red">&lt;?=form_error('email');?&gt;</font>
        Email: &lt;?=form_input($email);?&gt;</br>
        <font color="red">&lt;?=form_error('first');?&gt;</font>
        <font color="red">&lt;?=form_error('middle');?&gt;</font>
        <font color="red">&lt;?=form_error('last');?&gt;</font>
        Name: &lt;?=form_input($first);?&gt; &lt;?=form_input($middle);?&gt; &lt;?=form_input($last);?&gt;</br>
        &lt;?=form_submit($submit);?&gt;</br>
        
        &lt;/form&gt;
    </td>
</tr>
</table></center>

&lt;?php include "footer.php" ?&gt;



[solved] set_value with form_input - El Forum - 08-16-2011

[eluser]xtremer360[/eluser]
It appears that you are calling a variable called $username for the form input in the html but you don't have it defined anywhere so I suggest you turn:

Code:
$data['username'] = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => set_value('username'),
              'maxlength'   => '24',
              'size'        => '24',
              'style'       => '',
            );

into

Code:
$username = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => set_value('username'),
              'maxlength'   => '24',
              'size'        => '24',
              'style'       => '',
            );



[solved] set_value with form_input - El Forum - 08-16-2011

[eluser]Bianca Migueis[/eluser]
but everything else works perfectly fine with $data[username]... I checked the view source and only thing that is not set as it should is the value...

EDIT: I figured it out. nothing like a good night of sleep to give you some perspective... Apparently the set_value function needs to be run after the $this->form_validation->run() so I just transfered my array to inside the if clause. now it works perfectly with this code:

Code:
public function index()
    {
        $data['loggedin'] = $this->cookie->checkcookie();
        
        
        
        if ($this->form_validation->run('register') == FALSE)
        {
            $data['username'] = array(
                  'name'        => 'username',
                  'id'          => 'username',
                  'value'       => set_value('username'),
                  'maxlength'   => '24',
                  'size'        => '24',
                  'style'       => '',
                );
            $data['password'] = array(
                  'name'        => 'password',
                  'id'          => 'password',
                  'value'       => set_value('password'),
                  'maxlength'   => '24',
                  'size'        => '24',
                  'style'       => '',
                );
            $data['password2'] = array(
                  'name'        => 'password2',
                  'id'          => 'password2',
                  'value'       => set_value('password2'),
                  'maxlength'   => '24',
                  'size'        => '24',
                  'style'       => '',
                );
            $data['first'] = array(
                  'name'        => 'first',
                  'id'          => 'first',
                  'value'       => set_value('first'),
                  'maxlength'   => '24',
                  'size'        => '24',
                  'style'       => '',
                );
            $data['middle'] = array(
                  'name'        => 'middle',
                  'id'          => 'middle',
                  'value'       => set_value('middle'),
                  'maxlength'   => '24',
                  'size'        => '24',
                  'style'       => '',
                );
            $data['last'] = array(
                  'name'        => 'last',
                  'id'          => 'last',
                  'value'       => set_value('last'),
                  'maxlength'   => '24',
                  'size'        => '24',
                  'style'       => '',
                );
            $data['email'] = array(
                  'name'        => 'email',
                  'id'          => 'email',
                  'value'       => set_value('email'),
                  'maxlength'   => '128',
                  'size'        => '50',
                  'style'       => '',
                );
            $data['submit'] = array(
                  'name'        => 'register',
                  'id'          => 'register',
                  'value'       => 'Register',
                  'maxlength'   => '24',
                  'size'        => '24',
                  'style'       => '',
                );
            $this->load->view('register_view', $data);
        }
        else
        {
            $this->updateDB($_POST);
        }
        
    }



[solved] set_value with form_input - El Forum - 08-16-2011

[eluser]xtremer360[/eluser]
Well everything looks right to me. Hopefully someone else will answer because I'd like to know for myself.