2011-10-31 102 views
0

我创建了一个搜索表单,我希望在提交时转发。Codeigniter表单,提交时重定向页面

它应该工作的方式是用户输入他们要搜索的内容,形式,然后将它们转发到/搜索/ $关键字的字词/关键字

我的研究已经让我的结论是,表单需要发布给控制器,然后从那里进行转发。但我已经尝试过无数次,无法将其推向前进。

这里是形式:

<?php echo form_open('search'); ?> 
      <input id="search_text" name="searchquery" type="text" value="enter your search here..." onfocus="if(this.value == 'enter your search here...') this.value='';" onblur="if(this.value == '') this.value='enter your search here...';" maxlength="120" > 
     <?php echo form_close();?> 

而且控制器:

if($this->input->post('searchquery')){ 
redirect('search', $this->input->post('searchquery')); 
} 

回答

2

改变这一行:

redirect('search', $this->input->post('searchquery')); 

到:

redirect('search/' . $this->input->post('searchquery')); 

在您的重定向呼叫时,第二个参数是重定向的“方法”,所以这就是重定向不起作用的原因。你想要的是这样的:

redirect('search/my+search+term'); 

这就是为什么我们做字符串连接,而不是将搜索项传递给第二个参数。

1

试试这个。

if($this->input->post('searchquery')){ 
redirect('search/'.$this->input->post('searchquery')); 
} 

您错误地使用了重定向方法。以下是文档摘录。

可选的第二个参数,可以让你的 “位置”的方法(默认值)或“刷新”方法之间进行选择。位置是 快,但在Windows服务器上它有时是一个问题