trouble with simple paths when i post |
[eluser]André Padez[/eluser]
Hey everyone, this is my first post here and i'm really new to codeigniter and to the MVC model, although i have experience in programming with php. This is my problem: I have [.htaccess] configured for [mod_rewrite], i have [uri_protocol] set to [Auto]. The url to my site is [http://localhost/myapp] So i have a controller, [Registration] where i call a view with a registration form, setup like this: Code: <form action="Registration/Register" method="post"> the first time i hit submit, it posts and it returns from the function, as expected, and the url changes to [http://localhost/myapp/Registration/Register] but if i click submit again, it doesn't run the function as it keeps adding "Registration/" to my url, ie, the second time i click i get [http://localhost/padezcms/Registration/R...n/Register] and the third [http://localhost/padezcms/Registration/R...n/Register], etc. Can anyone please give me a hand with this? i'm really stuck. Thanx
[eluser]w3ttr3y[/eluser]
The problem is that you are using relative URL's. The first time this works because you are accessing http://localhost/myapp/ so when it sees Registration/Register then it just appends it to the end. The way to fix this is to always use absolute URL's. Since you still want to be portable in case you move your code look into using the base_url function (http://ellislab.com/codeigniter/user-gui...elper.html).
[eluser]InsiteFX[/eluser]
You can also look into the form_validation and form_help in the CodeIgniter User Guide! Form_Validation: Form_Validation Class Form_Helper: form_helper InsiteFX
[eluser]nuwanda[/eluser]
Yeah, use the form helper that CI provides. Code: echo form_open('controller/method'); CI will prepend the site url.
[eluser]André Padez[/eluser]
thank you very much everyone, i'm going to try it just as soon i finish some work for my employer
[eluser]André Padez[/eluser]
hey, i tried using the base_url() and it works perfectly. I could use the form helper, but i was looking for a more global solution since i was also having trouble with my ajax calls, etc. Once again, thank you very much |
Welcome Guest, Not a member yet? Register Sign In |