I'm trying to implement search form to my website using Codeigniter 3.0 and I'm having some issues with redirect()
method.
What I want to do is when I type some string and press enter, it will do a post request to a controller then the controller will get the string and redirect current url to http://example.com/search/string
So, here are the codes that I have:
Search form:
<form action="/search" method="post" accept-charset="UTF-8">
A controller which gets search string and do redirect:
public function do_search() {
$search = $this->input->post('search');
log_message('debug', 'search: ' . $search);
if ($search) {
redirect('search/' . $search, 'refresh');
} else {
redirect('/', 'refresh');
}
}
config.php:
$config['permitted_uri_chars'] = 'üÜöÖğĞıİəƏçÇşŞ a-z 0-9~%.:_\-';
Also, I have following code on my base controller: MY_Controller
$this->output->set_header('Content-Type: text/html; charset=utf-8');
Now, when I type "həə" on my search form, it does redirect, but url becomes like "hÉÉ" . As you see I'm logging search string on my controller, which prints correctly. (like "həə" ).
Am I missing something? Any ideas how to solve this?
Non ascii support is a general problem in software and it is a very special problem in browser related software. What you should do is, fetch the incoming values and have a kind of logic and do a remap. Codeigniter has a build in remap function.
It is called by:
function _remap($method)
{
// here your logic
}
You can have this function in every controller.
A small tipp: If you are supporting multi-languages, then you should transfer on every request the language in your GET or POST or Cookie and have a kind of logic. Otherwise you will have trouble.
I wrote a small jQuery code to do redirection, and it did work in my case.
$("form[name=search]").submit(function (e) {
e.preventDefault();
window.location = "/search/" + $("input[name=search]").val();
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.