Welcome Guest, Not a member yet? Register   Sign In
method GET in search result

Hi everybody,

i'm coding a search function that at the form submit, send GET data like this:


but i like this url


there is a function or configuration or something in CI that makes this without a rewrite role?

I have used two ways to do that.

1. Use Javascript to handle the form. Before submitting the form, you change the form's "action" attribute, using the form's values. Something like:
<form name="myform" action="" method="post">
(your input fields here)

function onformsubmit(myform)
myform.action = '/search/result/' + myform.from.value + '/' + myform.search.value + '';
return true;

2. Use a forwarding mechanism. You send the form (with POST). In CodeIgniter, you rewrite the address and forward to a new page. Something like:
$url = site_url('search','result',$this->input->post('from'),$this->input->post('search'));

i think the second one is the best for my idea, beacause if i put in a robot.txt some urls like search/result/var1/var2 the robots can find a page and i think this is something good for google.

i don't know if i'm explain.


it works fine with the your second solution but i change the code:

function index()
        //$url = site_url('search','risultato',$this->input->post('from'),$this->input->post('search'));
        $url =  base_url().'search/risultato/'.$this->input->post('from').'/'.$this->input->post('search');

    function risultato()
        $data['query'] = $this->search->get_search_result($this->uri->segment(3), $this->uri->segment(4));
        $this->template->parse_view('content', 'inc/risultato_ricerca_view', $data);

'cause header didn't work and i change the url var in another way.is it correct?

Oh, I'm sorry, I was too quick with the header. It should be : header('Location: ' . $url);
But redirect() is fine; that basically does the same thing and it even has some more possibilities.

Seems fine to me. I am glad it worked for you!

Theme © iAndrew 2016 - Forum software by © MyBB