CodeIgniter Forums
form_open adds index.php to path - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forum-5.html)
+--- Forum: General Help (https://forum.codeigniter.com/forum-24.html)
+--- Thread: form_open adds index.php to path (/thread-72345.html)



form_open adds index.php to path - Fabatka - 12-07-2018

Hi,
Using form_open('your/path') adds the index.php to the absolute path in the final HTML while using base_url('your/path') does not.
Posting form data is not working when I use .htaccess to remove index.php from the path AND index.php is part of the absolute path. 
I suggest removing index.php from all CI generated path in the future so all functions will output a path like base_url for consistency.

If you have the same problem as I had not being able to post form data using form_open() you can use the following code instead:
<form action="<?= base_url('your/path')?>" method="post" accept-charset="utf-8"> 

I use the following code in .htaccess to remove index.php and redirect:

#1) redirect the client from "/index.php/foo/bar" to "/foo/bar"
RewriteCond %{THE_REQUEST} /index\.php/(.+)\sHTTP [NC]
RewriteRule ^ /%1 [NE,L,R]
#2)internally map "/foo/bar" to "/index.php/foo/bar"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]


RE: form_open adds index.php to path - kaitenz - 12-12-2018

(12-07-2018, 03:56 AM)Fabatka Wrote: Hi,
Using form_open('your/path') adds the index.php to the absolute path in the final HTML while using base_url('your/path') does not.
Posting form data is not working when I use .htaccess to remove index.php from the path AND index.php is part of the absolute path. 
I suggest removing index.php from all CI generated path in the future so all functions will output a path like base_url for consistency.

If you have the same problem as I had not being able to post form data using form_open() you can use the following code instead:
<form action="<?= base_url('your/path')?>" method="post" accept-charset="utf-8"> 

I use the following code in .htaccess to remove index.php and redirect:

#1) redirect the client from "/index.php/foo/bar" to "/foo/bar"
RewriteCond %{THE_REQUEST} /index\.php/(.+)\sHTTP [NC]
RewriteRule ^ /%1 [NE,L,R]
#2)internally map "/foo/bar" to "/index.php/foo/bar"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [L]

Did you check your config.php file?

Set this to your config file:
PHP Code:
$config['index_page'] = ''

Also, I suggest using form_open if you have CSRF enabled.