Welcome Guest, Not a member yet? Register   Sign In
Form help & receiving the data
#1

[eluser]Kinsbane[/eluser]
Hi all!

So, I've got a form that looks like this:
Code:
<form method="GET" action="/browse/category/" onchange="form.submit();">
<select name="category">
<option value="Category1">Category 1</option>
<option value="Category2">Category 2</option>
</select>
&lt;/form&gt;

I did a test switch, and when I do, the form submits and I get sent to /browse/category/ but my URL ends up being this: browse/category/?category=Category1

However, I would like it so that browse is my controller, category is the function, and the actual category is what gets passed, so the URL would end up looking like so: browse/category/Category1

Is something I need to change in the URI routing, or some other place? Or do I have to program my own solution to get what I'm looking for? My config is currently set to FALSE for $config['enable_query_strings']

Thanks!
#2

[eluser]gtech[/eluser]
try using

Code:
&lt;form method="POST" action="&lt;?=site_url()?&gt;/browse/category/"&gt;
&lt;select name="category" onchange="form.submit();"&gt;
<option value="Category1">Category 1</option>
<option value="Category2">Category 2</option>
</select>
&lt;/form&gt;

you should be using POST as opposed to GET in this instance, you might also want to take a look at the form and validation helpers. GETs are nasty as they send the form data through the URL, thats why you get the ?category=Category2 on the end. A POST will send the form data through the http request.

If using the post method you can retrieve the data in the controller your posting to by doing

Code:
$category = $this->input->post('category', TRUE);

site_url() will ensure the full URL is used (your config has to have base_url and index_page setup correctly.




Theme © iAndrew 2016 - Forum software by © MyBB