Reputation: 8700
I am new to codeigniter, I am adding a search function to the site, and had two questions.
Thanks for any help, Max
Upvotes: 0
Views: 3369
Reputation: 10114
You would use JavaScript to form the URL, like this:
<form onsubmit="window.location.href='/search/'+encodeURIComponent(document.getElementById('search_query').value);return false">
<input id="search_query" type="text" />
<input type="submit" />
</form>
EDIT: The above answer will not work because of CodeIgniter's URI filter. However, from my experience with version 1.7, if you pass more than one GET parameter, you can retrieve them using the $_REQUEST array. This will bypass the URI filter altogether. So do this:
<form action="/search">
<input name="x" type="hidden" />
<input name="q" type="text" />
<input type="submit" />
</form>
Then use $_REQUEST['q'] to get your search query. Hopefully this will work for you.
Upvotes: 3
Reputation: 11490
if you need to use something like
index.php?c=search&m=search&q=wow
instead of CI's default URI Segments
you have to enable query strings . you can do it by changing some configuration in
application/config.php
find
$config['enable_query_strings'] = FALSE;
and change it to
$config['enable_query_strings'] = TRUE;
Then you will be able to use query strings .
but mots CI people prefer not to use query strings, I am not sure why .
Upvotes: 0
Reputation: 24969
method="get"
.Example:
<form action="example.php" method="get">
<input type="text" name="search" />
<input type="submit" value="Search" />
</form>
Update: To generate the form the "CodeIgniter" way:
echo form_open('email/send', array('method' => 'get'));
Upvotes: 0