<?php echo validation_errors(); ?>
<?php echo form_open('form'); ?>
<input type="text" name="something" />
<input type="submit" value="submit"/>
</form>
我发现
中没有“动作”和“方法”<form action="/application/controler/somepage.php" method="POST">
</form>
我希望在按下提交按钮后获取在文本框中输入的值。我怎么能这样做(通过POST或GET提交的值),如前一样?
另外,如果我想获取URL中传递的值
http://localhost/index.php/something?value=75&today=Wed
75
和Wed
。
答案 0 :(得分:16)
试试这个:
echo form_open('controller/somepage', array('method'=>'get'));
答案 1 :(得分:6)
CodeIgniter Form Helper Documentation表示您传递到form_open()
函数的第一个参数是您要发布到的网址。 URL语义是CodeIgniter的重要组成部分,如果您要发布到应用程序内的某个位置,请使用:
<?= form_open('index.php/controller/function/param1/param2');?>
CodeIgniter默认使用method='post'
。
CodeIgniter本身不支持表单method='get'
参数,因为它处理URL的方式。而不是URL:
http://localhost/myapp/index.php/something?value=75&today=Wed
CodeIgniter的方式是:
http://localhost/myapp/index.php/mycontroller/myfunction/75/Wed
然后,您将在控制器中定义一个函数
function myfunction($value, $day)
{
//do whatever you want with the $value and the $day here.
}
答案 2 :(得分:1)
尝试:
echo form_open('controller/somepage');
查看文档:
答案 3 :(得分:0)
如果您希望将更改方法设为GET
,则必须将该属性添加到form_open()
$attribute['method'] = 'get';
echo form_open(THE_ACTION_URL, $attribute);
或者,您可以创建自己的helper
以获得更快的方法
function form_open_get($action, $attribute = NULL, $hidden = NULL)
{
$attribute['method'] = 'get';
return form_open($action,$attribute,$hidden);
}
答案 4 :(得分:0)
在表单之前定义属性,例如:
$attributes = 'method="get"';