[英]Codeigniter form, redirect page on submit
我创建了一个搜索表单,希望在提交时转发。
它的工作方式是用户输入要搜索的字词/关键字,然后表单会将其转发到/ search / $ keyword
我的研究使我得出以下结论:需要将表单过帐到控制器,然后从那里进行转发。 但是我已经尝试了很多次,无法继续前进。
形式如下:
<?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'));
}
更改此行:
redirect('search', $this->input->post('searchquery'));
至:
redirect('search/' . $this->input->post('searchquery'));
在您的重定向调用中,第二个参数是重定向的“方法”,因此这就是您的重定向不起作用的原因。 您想要的是这样的:
redirect('search/my+search+term');
这就是为什么我们要进行字符串连接,而不是将搜索项传递给第二个参数。
试试这个吧。
if($this->input->post('searchquery')){
redirect('search/'.$this->input->post('searchquery'));
}
您使用的重定向方法不正确。 这是该文档的摘录。
可选的第二个参数允许您在“位置”方法(默认)或“刷新”方法之间进行选择。 位置更快,但在Windows服务器上有时可能会出现问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.