Registration method is not done PHP

0

I hope someone can help me with the following detail. First of all put the code. It happens that, once I click on save, it does not mark me an error, but rather that the browser stays in the controller -register- and does not do more. I do not know what detail I should have around there. Thanks for taking the time to review my problem.

Model

    public function guardarC(
    $CURP, $nombre, $ap_P, $ap_M, $num_tel, $id_localidad, $id_colonia, 
    $referencia) {

    $ciudadano = array(
        'CURP'         => $CURP,
        'nombre'       => $nombre,
        'ap_P'         => $ap_P,
        'ap_M'         => $ap_M,
        'num_tel'      => $num_tel,
        'id_localidad' => $id_localidad,
        'id_colonia'   => $id_colonia,
        'referencia'   => $referencia,
    );
    $this->db->insert('cat_ciudadanos', $ciudadano);
}

Driver

    public function registrar()
{
    if ($this->input->post('submit')) {

        $this->form_validation->set_rules('CURP', 'CURP', 'required');
        $this->form_validation->set_rules('nombre', 'nombre', 'required');
        $this->form_validation->set_rules('ap_P', 'ap_P', 'required');
        $this->form_validation->set_rules('ap_M', 'ap_M', 'required');
        $this->form_validation->set_rules('num_tel', 'num_tel', 'required');
        $this->form_validation->set_rules('id_localidad', 'id_localidad', 'required');
        $this->form_validation->set_rules('id_colonia', 'id_colonia', 'required');
        $this->form_validation->set_rules('referencia', 'referencia', 'required');

        if ($this->form_validation->run() == true) {
            $CURP         = $_POST['CURP'];
            $nombre       = $_POST['nombre'];
            $ap_P         = $_POST['ap_P'];
            $ap_M         = $_POST['ap_M'];
            $num_tel      = $_POST['num_tel'];
            $id_localidad = $_POST['id_localidad'];
            $id_colonia   = $_POST['id_colonia'];
            $referencia   = $_POST['referencia'];

            $datos = $this->Registros_model->guardarC(
                $CURP,
                $nombre,
                $ap_P,
                $ap_M,
                $num_tel,
                $id_localidad,
                $id_colonia,
                $referencia
            );

            redirect('ayuntamiento/registroC', 'refresh');
        }
    }
}

Vista

<div class="container">
<form id="form" name="form" method="POST" action="<?php echo base_url(); ?>ayuntamiento/registrar">
<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="form-group">
            <label for="CURP">C U R P</label>
            <input class="form-control" type="text" id="CURP" placeholder="C U R P">
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-md-offset-3">
         <div class="form-group">
             <label for="nombre">Nombre</label>
             <input class="form-control" type="text" id="nombre" placeholder="Nombre (s)">
         </div>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="form-group">
            <label for="ap_P">Primer Apellido</label>
            <input class="form-control" type="text" id="ap_P" placeholder="Apellido Paterno">
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="form-group">
            <label for="ap_M">Segundo Apellido</label>
            <input class="form-control" type="text" id="ap_M" placeholder="Apellido Materno">
        </div>
    </div>
 </div>

<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="form-group">
            <label for="telefono">Numero Telefonico</label>
            <input class="form-control" type="text" id="num_tel" placeholder="Numero Telefonico">
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="form-group">
            <label>Dirección</label>
            <br>
            <select  class="form-control" id="id_localidad" name="id_localidad" style="background-color: #A9A9A9">
                <option value="0">Localidades</option>
                <?php foreach ($localidades as $i) {?>
                 <option value="<?php echo $i->id_localidad; ?>"><?php echo $i->nombre; ?></option>;
                <?php }?>
            </select>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="form-group">
            <select class="form-control" id="id_colonia" name="id_colonia" style="background-color: #A9A9A9">
                <option value="0">Colonias</option>
                <?php foreach ($colonias as $i) {?>
                 <option value="<?php echo $i->id_colonia; ?>"><?php echo $i->nombre; ?></option>;
                <?php }?>
            </select>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-md-offset-3">
        <div class="form-group">
            <label for="referencia">Referencia</label>
            <textarea class="form-control" rows="5" id="referencia"></textarea>
        </div>
    </div>
</div>

    <div class="container">
        <button type="submit" class="btn btn-primary center-block">
        <span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>
        Guardar
        </button>
    </div>
</form>

    
asked by RMustang 10.10.2017 в 22:34
source

1 answer

0

I have not used Codeigniter for some time, but on your controller the first if

if($this->input->post('submit')){
   ...

would return NULL , which is a falsy value, because there is no input on your form that has the name submit. Therefore, the content of the if is never executed. More information about the library input

If you want to know if the form was sent by POST you should ask like this:

if ($this->input->method() === 'post') {

Greetings.

    
answered by 11.10.2017 / 03:34
source