Welcome Guest, Not a member yet? Register   Sign In
Best way to populate an edit form from a database
#16

[eluser]satanuzo[/eluser]
Mi metodo

CONTROLLERS

Para cargar la vista

Code:
public function add_ciudad(){

        $data['data_form']          = $this->session->flashdata('data_form');
        $data['insertar_otro']      = $this->session->flashdata('insertar_otro');
        
        $data['opt_region']         = $this->localidad_model->opt_region();
        
        $data['url_navegacion']     = anchor('localidad/list_ciudad/listar/'.$this->session->userdata('offset').'',$this->titulo_nav_2).' > '.'Nueva ciudad';
        $data['url_accion']         = site_url('localidad/insert_ciudad');

        $this->load->view('head');
        $this->load->view('localidad_ciudad_insert', $data);
        $this->load->view('foot');
    }


Para insertar

Code:
public function insert_ciudad(){

        $data_form          = $this->input->post('data_form');
        $insertar_otro      = $this->input->post('insertar_otro');

        $msg = '';
        $this->form_validation->set_rules('data_form[id_region]', 'Región', 'trim|required|xss_clean');
        $this->form_validation->set_rules('data_form[nombre_ciudad]', 'Nombre', 'trim|required|min_length[3]|xss_clean|callback_ciudad_check');
        

        // run validation
        if ($this->form_validation->run() == FALSE){
            $msg['error'] = 'No se pudo ingresar la ciudad, intentelo nuevamente.<br />'.validation_errors();
            $this->session->set_flashdata('msg', $msg);
            $this->session->set_flashdata('data_form', $data_form);
            $this->session->set_flashdata('insertar_otro', $insertar_otro);
            redirect('localidad/add_ciudad','location', 301);
        }else{
            $id_region = $this->localidad_model->insert_ciudad($data_form);
            $msg['ok'] = 'La ciudad ha sido ingresada.';
            $this->session->set_flashdata('msg', $msg);
            if ($insertar_otro == 'on'){
                $this->session->set_flashdata('insertar_otro', $insertar_otro);
                redirect('localidad/add_ciudad','location', 301);
            }else{
                redirect('localidad/list_ciudad/listar/'.$this->session->userdata('offset').'','location', 301);
            }
        }
    }

VIEWS

Code:
<div class="content">
    <div class='tible'>&lt;?=$url_navegacion;?&gt;</div>
    &lt;?=form_open($url_accion)?&gt;
        <div class="data_form">
            <table>
                <tr>
                    <th width="30%">Regi&oacute;n<span class="requerido">&nbsp;*</span></th>
                    <td>&lt;?=form_dropdown('data_form[id_region]', $opt_region, $data_form['id_region'])?&gt;</td>
                </tr>
                <tr>
                    <th width="30%">Nombre<span class="requerido">&nbsp;*</span></th>
                    <td>&lt;?=form_input('data_form[nombre_ciudad]', $data_form['nombre_ciudad'])?&gt;</td>
                </tr>
                <tr>
                    <th>&nbsp;</th>
                    <td>&lt;?=form_submit('guardar','Guardar')?&gt;&nbsp;&lt;?=form_checkbox('insertar_otro','on', ($insertar_otro == 'on' ? TRUE : FALSE))?&gt;INSERTAR OTRO</td>
                </tr>
            </table>
        </div>
    &lt;?=form_close()?&gt;
    <br />
</div>


Messages In This Thread
Best way to populate an edit form from a database - by El Forum - 04-30-2009, 09:19 AM
Best way to populate an edit form from a database - by El Forum - 04-30-2009, 10:14 AM
Best way to populate an edit form from a database - by El Forum - 04-30-2009, 10:25 AM
Best way to populate an edit form from a database - by El Forum - 05-01-2009, 10:01 AM
Best way to populate an edit form from a database - by El Forum - 05-22-2009, 10:15 AM
Best way to populate an edit form from a database - by El Forum - 05-24-2009, 02:02 AM
Best way to populate an edit form from a database - by El Forum - 05-24-2009, 07:19 PM
Best way to populate an edit form from a database - by El Forum - 01-05-2010, 07:10 PM
Best way to populate an edit form from a database - by El Forum - 01-05-2010, 07:33 PM
Best way to populate an edit form from a database - by El Forum - 01-06-2010, 07:02 AM
Best way to populate an edit form from a database - by El Forum - 01-08-2010, 08:20 AM
Best way to populate an edit form from a database - by El Forum - 02-15-2010, 07:06 AM
Best way to populate an edit form from a database - by El Forum - 03-31-2010, 05:58 AM
Best way to populate an edit form from a database - by El Forum - 03-31-2010, 09:03 AM
Best way to populate an edit form from a database - by El Forum - 03-23-2011, 11:33 AM
Best way to populate an edit form from a database - by El Forum - 07-06-2011, 01:40 PM
Best way to populate an edit form from a database - by El Forum - 07-06-2011, 01:45 PM
Best way to populate an edit form from a database - by El Forum - 07-06-2011, 02:57 PM



Theme © iAndrew 2016 - Forum software by © MyBB