PHP获取表单问题

PHP获取表单问题,php,forms,post,get,show,Php,Forms,Post,Get,Show,我有以下引述: <form class="searchform" name="search" id="search" action="<?php echo base_url();?>video/search" method="get" > <input type="text" name="search_key" onblur="if (this.value == '') {this.value = 'Search video';}"

我有以下引述:

<form class="searchform" name="search" id="search" action="<?php echo base_url();?>video/search" method="get" >
                <input type="text" name="search_key" onblur="if (this.value == '') {this.value = 'Search video';}" onfocus="if (this.value == 'Search video') {this.value = '';}" value="<?php if(isset($search_key))echo $search_key;else echo 'Search video';?>" class="searchfield" onKeyPress="return submitenter(this,event)">
        </form>
我用来展示的代码是:

<?php echo $_GET["search_key"]; ?>

但它不起作用,我不明白为什么


我无法使-blabla-出现在页面中。

请查看
$\u GET
超级全局中是否有任何值,方法是使用
var\u dump($\u GET)
将不太漂亮的对象字符串转储到屏幕上

还可以尝试
$\u请求
$GLOBALS
变量,并通过执行上述操作查看它们是否有任何值

如果这些没有显示您的值,您可能需要强制设置表单的
enctype
,以便PHP知道它可以将查询字符串(从
开始的文本)或POST数据带入超级全局。您要使用的
enctype
application/x-www-form-urlencoded
,以防万一,请设置它

设置后,您的表单将如下所示

<form class="searchform" name="search" id="search" action="<?php echo base_url();?>video/search" method="get" enctype="application/x-www-form-urlencoded">
    <input type="text" name="search_key" onblur="if (this.value == '') {this.value = 'Search video';}" onfocus="if (this.value == 'Search video') {this.value = '';}" value="<?php if(isset($search_key))echo $search_key;else echo 'Search video';?>" class="searchfield" onKeyPress="return submitenter(this,event)" />
</form>

如果显示URL
/search?search_key=blablabla
,请尝试使用
$\u POST
并使用
打印($\u POST)
,因为CI上的默认表单方法是使用POST。

要从查询字符串中获取值,必须将查询字符串设置为true

去 1) application/config/config.php 2) 将查询字符串选项设置为true

例如$config['enable_query_strings']=true

您可以获得$\u get[“search\u key”]

其他明智的做法是发送值,如

mypage.com/video/search/blabla

您将在cideo控制器的搜索函数的第一个参数中获得“blabla”。

您的
操作
表单
标记中,应该是一个类似
myphp.PHP
的PHP文件,然后您可以使用
$\u get[
[“search\u key'];
myphp`处获取它。例如

action="<?php echo base_url();?>video/search/myphp.php"
action=“video/search/myphp.php”

然后URL应该像
mypage.com/video/search/myphp.php?search_key=blablabla

mypage.com/video/search
一个php文件吗?
action="<?php echo base_url();?>video/search/myphp.php"