Monday, March 18, 2013

Make a login form using CodeIgniter

At first make a controler by writing the code below:
<?php
    class FormCon extends CI_Controller{
        function __construct(){
            parent::__construct();
        }
       
        function show(){
            $this->load->helper('form');
            $this->load->view('formviewer');
        }
    }
?>

Give the file name FormCon.php and save it codeigniter\application\controllers\FormCon.php.

Then make a view by writing the code below:

 
<?php
    form_open('actionPageName');
   
    $data = array(
                'name' => 'username',
                'size' => '25'
            );
    echo "User Name: ".form_input($data);
   
    $data = array(
                'name' => 'password',
                'size' => '25'
            );
    echo "Password: ".form_input($data);
?>


Give the file name formviewer.php and save it codeigniter\application\views\formviewer.php.

Then write http://localhost/codeigniter/index.php/FormCon/show/ into your browser and see the magic.  Here FormCon is your controller class name and show is that controler's function name.

No comments:

Post a Comment