How to make dynamic form action address in codeigniter?

后端 未结 1 1744
没有蜡笔的小新
没有蜡笔的小新 2020-12-11 08:51

I have a search form on my site, and it looks like this:

相关标签:
1条回答
  • 2020-12-11 09:12

    I would use jQuery

    $('#myform').submit(function(){
        $(this).attr('action', $(this).attr('action') + "/" + $(this).find(input[name="keyword"]).val());
    });
    

    Another possibility is to make a proxy method in your controller, it's useful if you want to have all your post values in the url:

    public function post_proxy() {
        $seg1 = $this->input->post('keyword');
        $seg2 = $this->input->post('keyword2');
        $seg3 = $this->input->post('keyword3');
    
        redirect('my_method/'.$seg1.'/'.$seg2.'/'.seg3);
    }
    

    In that case I would use arrays in post data to simplify code:

    <input type="text" name="kw[1]">
    <input type="text" name="kw[2]">
    <input type="text" name="kw[3]">
    
    $segment_array = $this->input->post('kw');
    $segments = implode("/", $segment_array);
    redirect('my_method'.$segments);
    
    0 讨论(0)
提交回复
热议问题