• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
form_open adds index.php to path

#1
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]
Reply

#2
(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.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2018 MyBB Group.