• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Root paths for form submit

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:-

<form name="logout" id="logout" method="post" action="logout">
<label>input type="submit" class="btn" value="Logout" name="logout" align="middle"/></label>

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:-

&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>

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

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

Or just use
&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

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!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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