CodeIgniter Forums
form_validation simple example - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: form_validation simple example (/thread-18450.html)



form_validation simple example - El Forum - 05-06-2009

[eluser]Ray Luevano[/eluser]
Esto es solo por compartir la ayuda que me brindo jozeunico :-)

la vista

Code:
<html>
<head>
<title>Welcome to CodeIgniter</title>

</head>
<body>

<?php
    echo form_open('validar');
        $data = array('name'=>'nombre', 'id'=>'nombre');
        echo 'Nombre:'.form_input($data);
      
        $data = array('name'=>'telefono', 'id'=>'telefono');
        echo 'Telefono:'.form_input($data);
      
        echo form_submit('submit','Validar');
    echo form_close();
?>
</body>
</html>

Controlador (Validacion)

Code:
<?php

class Validar extends Controller {

    function Validar()
    {
        parent::Controller();  
    }
  
    function index()
    {
        $this->load->library('form_validation');
        $this->load->view('welcome_message');
      
        $this->form_validation->set_rules('nombre', 'El nombre', 'required');
        $this->form_validation->set_rules('telefono', 'El telefono', 'required|numeric|integer');

      
        if ($this->form_validation->run() == FALSE)
        {
        echo "ERROR";
        echo validation_errors();
        }
        else
        {
        echo "exito";
        }
    }
}


Controlador (Vista)

Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();  
    }
  
    function index()
    {
        $this->load->helper('form');
        $this->load->view('welcome_message');
    }
}
?>