Welcome Guest, Not a member yet? Register   Sign In
form_open problem
#1

[eluser]Unknown[/eluser]
I'm depressingly noob at this, and I am pulling my hair out on this one.

I have created a form that uses form_open to point to a controller:
Code:
<?php echo form_open('mycontroller'); ?>

When the form is loaded in a browser, the page source shows the correct html:
Code:
<form action="localhost/index.php/mycontroller" method="post" accept-charset="utf-8">

However, when the submit button is clicked, I get a 404 error and the URL looks like this:
Code:
http://localhost/index.php/mycontroller/localhost/index.php/mycontroller

Why am I getting that ridiculous URL?
#2

[eluser]srpurdy[/eluser]
either do this.

make sure base_url has http:// in it

Also try these.. the problem is the form action isn't correct, it should be mycontroller only or have the http:// in it.

Code:
<?php echo form_open('/mycontroller');?>

or

Code:
<?php echo form_open(base_url().'mycontroller');?>

So a valid form action should look like either of these two.

Code:
<form action="mycontroller" method="post" accept-charset="utf-8">  

<form action="http://localhost/index.php/mycontroller" method="post" accept-charset="utf-8">

#3

[eluser]CroNiX[/eluser]
Yes, your base_url is probably not set correctly in your config.

It looks like for you it should be exactly (including the http and the last /):
http://localhost/
Then
Code:
echo form_open('mycontroller');
will work correctly.

If you have that set wrong forms are not the only thing that won't work properly, the anchor() function and others rely on that setting as well.
#4

[eluser]Unknown[/eluser]
Yep, I had base_url set to just 'localhost'. Setting it to 'http://localhost/' fixed the problem. I knew it was something simple and stupid, but I spent hours this morning trying to figure it out to no avail.

Thanks, guys! I feel sanity returning...




Theme © iAndrew 2016 - Forum software by © MyBB