Search code examples
phpcodeignitercodeigniter-2codeigniter-3

form_open() is not working peoperly


I have a controller named : user_login_controller.php and view : user_login_view.php code of user_login_view.php

 <?php echo form_open('user_login_controller/login', 'class="form-horizontal" id="userloginform"');?>
    <fieldset>
      <legend>Student Login</legend>
      <div class="form-group">
        <div class="col-lg-6 col-md-6 col-xs-10">
          <?php echo form_input(['name'=>'rno','class'=>'form-control','placeholder'=>'Roll Number'])?>
        </div>
      </div>
      <div class="form-group">
        <div class="col-lg-6 col-md-6 col-xs-10">
          <?php echo form_password(['name'=>'pwd','class'=>'form-control','placeholder'=>'Password'])?>
        </div>
      </div>
       <div class="col-lg-6 col-md-6 col-lg-offset-2 col-md-offset-2">
          <?php echo form_reset(['name'=>'Reset','value'=>'Cancel','class'=>'btn btn-primary'])?>
          <?php echo form_submit(['name'=>'Submit','value'=>'Login','class'=>'btn btn-primary'])?>
        </div>
      </div>
    </fieldset>
  </form>

On submit button click I m sending control to user_login_controller/login here is user_login_controller.php

<?php
class User_login_controller extends MY_Controller
{
    public function index()
    {
        $this->load->view('user/user_login_view');
    }
    public function login()
    {
        echo "User login function";
    }
}

?> but it's given me 404 error.however i have both files

and when I m going through url(http://localhost:8090/project/user_login_controller/login) :then its working. and i have loaded all the necessary helpers.

$autoload['helper'] = array('url','form');

what to do now?


Solution

  • You should set config['base_url'] in application/config/config.php

    $config['base_url'] = 'http://localhost:8090/project/';
    

    as form_open consider url to be set to http://localhost:80/project/ or http://[::1]/project/ if you didn't set config['base_url']