• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Put text in an form_input control

#1
[eluser]HugoA[/eluser]
Hi. I'm trying to make a form with some input controls and i need to put some info in those controls so the user can change the data. Basically what I'm doing is retrieve some data from the data base and then i need to put that data in the input fields. How can i do this?

this is mi view
Code:
<head>
    <title>Formulario</title>
    <link rel="stylesheet" href="<?php echo base_url();?>system/css/style.css" type="text/css" media="screen"
    charset="utf-8">
</head>
<body>
    <div id="container">
        <h1>Ejemplo de Formulario</h1>

        &lt;?php
            echo form_open('formulario/crearUsuario');
                    
        ?&gt;
                
        <fieldset>
            <legend>Informacion Personal</legend>
            <table>
                <tr>
                    <td>
                        &lt;?php echo form_label('Nombre:','labelNombre')?&gt;
                    </td>
                    <td>
                        &lt;?php
                            $nombreConfig = array(
                                'name' => 'nombre',
                                'id' => 'nombre',
                                'maxlength' => '10');
                            echo form_input($nombreConfig)
                        ?&gt;
                    </td>
                </tr>
                <tr>
                    <td>
                        &lt;?php echo form_label('Apellido:','labelApellido')?&gt;
                    </td>
                    <td>
                        &lt;?php
                            $apellidoConfig = array(
                                'name' => 'apellido',
                                'id' => 'apellido',
                                'maxlength' => '10');
                            echo form_input($apellidoConfig)
                        ?&gt;
                    </td>
                </tr>
                <tr>
                    <td>
                        &lt;?php echo form_label('Super Clave:','labelSuperClave')?&gt;
                    </td>
                    <td>
                        &lt;?php
                            $passwordConfig = array(
                                'name' => 'clave',
                                'id' => 'clave',
                                'maxlength' => '10',);
                            echo form_password($passwordConfig)
                        ?&gt;
                    </td>
                </tr>
            </table>
        </fieldset>
        &lt;?php echo form_close()?&gt;
    </div>
&lt;/body&gt;

this is the controller

Code:
&lt;?php

class Formulario extends Controller{
    
    function index()
    {
        $data = array();
        
        $this->load->model('formulario_model');
        if($query = $this->formulario_model->obtener_usuario())
        {
            $data['records'] = $query;
        }
        
        $this->load->view('formulario_view',$data);
    }
    
}

?&gt;

and this is the model
Code:
&lt;?php

class Formulario_model extends Model{
    
    function obtener_usuario()
    {
        $this->db->where('idpersona','1');
        $query = $this->db->get('persona');
        if($query->num_rows() > 0){
            foreach($query->result() as $row){
                $data[] = $row;
            }
            return $data;
        }
    }
    
}

?&gt;

Thanks!

#2
[eluser]Dyllon[/eluser]
Read the user guide for the Form Helper, specifically set_value()

#3
[eluser]HugoA[/eluser]
I just finished read the guide and i change mi code to this

Code:
<tr>
                    <td>
                        &lt;?php echo form_label('Nombre:','labelNombre')?&gt;
                    </td>
                    <td>
                    &lt;?php foreach($records as $row) : ?&gt;
                        &lt;?php
                            $nombreConfig = array(
                                'name' => 'nombre',
                                'id' => 'nombre',
                                'maxlength' => '10');
                            echo form_input($nombreConfig,set_value($row->nombre))
                        ?&gt;
                        &lt;?php endforeach;?&gt;
                    </td>
                </tr>

but i can't see the persons name on the input field. The person's name is in the db, i just want to put it on the field when i load the view.

#4
[eluser]HugoA[/eluser]
Done!

echo form_input($apellidoConfig,set_value('apellido',$row->apellido))

thanks Dyllon!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.