CodeIgniter Forums

Full Version: Root paths for form submit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Dandy_andy[/eluser]
I am using a global header for my site which has various options that dynamically change depending on the page being viewed. One of the issues I have is with form submits because of the controller paths. To try and explain this simply, one of the forms in my header template has the following:-

Code:
<form name="logout" id="logout" method="post" action="logout">
<label>input type="submit" class="btn" value="Logout" name="logout" align="middle"/></label>
&lt;/form&gt;

When the header is called up from a controller at say www.site.com/controller, then the "logout" controller is accessed fine.

But now I have added additional tiers to my controllers in order to create various site functions, I cant access the "logout" controller if I am at say www.site.com/user/controller as the post is looking for "logout" at that level.

Is there a simple way to create an absolute path without having to pass variables through the controller? I have tried the following but it doesn't work:-

Code:
&lt;form name="logout" id="logout" method="post" action="&lt;?php echo ($_SERVER['DOCUMENT_ROOT']); ?&gt;/logout"&gt;
          <label>input type="submit" class="btn" value="Logout" name="logout" align="middle"/></label>
                &lt;/form&gt;

El Forum

[eluser]PhilTem[/eluser]
Use the form_helper. It will fix your problems since all URLs are created with $config['base_url'] in mind.

Code:
echo form_open('logout');
will always point to example.com/logout

Or just use
Code:
&lt;form action="&lt;?php echo site_url('logout'); ?&gt;"&gt;

Will do the same yet just returning "example.com/logout" instead of the whole form-open tag Wink

And read the freakin doku, it won't bite Wink

El Forum

[eluser]Dandy_andy[/eluser]
I'm reading it honest, but I am completely new to PHP and codeigniter and considering I've only have around three weeks so far, I think I'm doing fairly well. Plus the docs don't always explain things very well to be honest but they are much better than other docs I've read and in general, ok. Thanks for the help!