Form action url not working in codeigniter

mohsin picture mohsin · Apr 21, 2017 · Viewed 7.6k times · Source

I am trying to use url in form action without using form helper in codeigniter but it's not working.

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

controller function

public function test(){
    echo "test function";
}

the error I am getting

http://prntscr.com/eyzhdd

Answer

Abdulla Nilam picture Abdulla Nilam · Apr 21, 2017

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.