I try to redirect a search to the right controller. This works fine if I have no special chars in the searchkey. If I have special keys in it I get an error from codeigniter:
The URI you submitted has disallowed characters.
Here is my code:
public function search()
{
$searchkey = urlencode($this->input->post('searchkey'));
switch ($this->input->post('searchtype')) {
case 'request': redirect('portal/requests/search/'.$searchkey, 'refresh');
break;
case 'offers': redirect('portal/offers/search/'.$searchkey, 'refresh');
break;
case 'projects': redirect('portal/projects/search/'.$searchkey, 'refresh');
break;
default: redirect('portal/requests/search/'.$searchkey, 'refresh');
break;
}
}
that is because you cannot put ‘special’ characters in your url
i.e. if I search for “test” I am taken to portal/projects/search/test
but if I search for test@#$)*&&f – you cannot have a url with some of those characters
to solve this either perform a validation on the post, and make the search term only have numbers and letters:
or you have to ‘pass’ the search term to function in another way – perhaps using flash data, so that the search term is not passed by a url
edit: default url chars for your reference (from line 129 (approx) of config.php)