Form action url not working in codeigniter Form action url not working in codeigniter codeigniter codeigniter

Form action url not working in codeigniter


It should be

<form method="post"  action="<?php echo base_url()?>index.php/main_controller/test">

as well base_url() should define as(application/config/config.php)

https://stackoverflow.com/                        ^ on the end$config['base_url'] = 'https://stackoverflow.com/'; # Line 26 if version 3.0+

<?php echo base_url()?>index.php/main_controller/test              ^            ^           ^           ^           base URL      index Controller Name   Method name

Check out the Codeigniter documentation.


<form method="post"  action="<?php echo base_url().'/main_controller/test/'; ?>">

Use Like this and define base url in http://www.example.com/ config.php file


In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php (around line 67):

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

Or, manually in controller:

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

Then change

<form method="post"  action="<?php echo base_url().'test'; ?>">  

to

<form method="post"  action="<?php echo base_url()?>index.php/main_controller/test">

Finally add base url in application/config/config.php. For instance,

$config['base_url'] = 'http://example.com/';

By default, the index.php file will be included in your URLs: You can remove index.php from action url with .htaccess file. Please read documenation