Codeigniter how to set form action url using form_open helper function Codeigniter how to set form action url using form_open helper function codeigniter codeigniter

Codeigniter how to set form action url using form_open helper function


You will need to pass complete url to the form_open function like this

<form action='http://localhost/folder/controller/method'>

There are two method to do this

1: Using base_url()

Step 1: Open the config.php file under application\config folder

step 2: Set the value of $config['base_url'] to your website path

  $config['base_url'] = "http://localhost/foldername/index.php";

How to use

Load the url helper in controller

 $this->load->helper('url);

Now in the view file you can use like this

  echo form_open(base_url()."/controllername/mehod");

2: Manually

   form_open("http://localhost/foldername/index.php/controller/method");


You will need to pass complete url to the form_open function like this

<form action='http://localhost/folder/controller/method'>

There are two method to do this

1: Using base_url()

Step 1: Open the config.php file under application\config folder

step 2: Set the value of $config['base_url'] to your website path

$config['base_url'] = "http://localhost/foldername/index.php";

How to use

Load the url helper in controller

$this->load->helper('url);

Now in the view file you can use like this

 echo form_open(base_url()."/controllername/mehod");

2: Manually

form_open("http://localhost/foldername/index.php/controller/method");


did you load helper (url,form) in your controllerif notthen u should make a load function in your controllerjust like this

public function load(){  $this->load->helper('url');$this->load->helper('form');}

and use this in function

    public function loginUser() {    $this->load();    $username = $this->mod_login->getUsername();    $inUser = $this->input->post('username');    $inPass = $this->input->post('password');    if (in_array($inUser, $username)) {        $password = $this->mod_login->getPassword($inUser);        if ($password === $inPass) {            $this->load->view('Alt_home');        }    }}