在 codeigniter 中获取除名称之外的表单值
你好,我正在使用 codeigniter 。我有一个表单,在那里我动态添加隐藏字段。因此每个隐藏字段都是 因此名称相等。
问题是,当我提交表单并尝试获取我的隐藏字段值时,我只能获取一个隐藏字段值,因为名称相同
我打印我的表单值
print_r($this->input->post());
我有 2 个隐藏字段,但我只得到一个
Array
(
[hidden] => march
[textbox] => march
[mysubmit] => Submit
)
我可以更改名称创建时动态隐藏字段,但是我不知道隐藏字段的确切名称,
如何获取具有相同名称的隐藏字段值?除了通过名称之外,还有什么方法可以获取表单值吗?我尝试过但找不到答案,请帮忙............
hi i am using codeigniter . i have a form , there i add hidden fields dynamically . so every hidden field is <input type='hidden' name='hidden' value="+$(this).attr('title')+">
so the name is equal .
the problem is when i submit the form and try to get my hiden field values i can only get one hidden field value , because the names are same
i print my form values
print_r($this->input->post());
i have 2 hidden fields but i get only one
Array
(
[hidden] => march
[textbox] => march
[mysubmit] => Submit
)
i can change the name dynamically of hidden field when creating , but then i don't know exactly the name of my hidden field ,
how can i get hidden field values with same name ?? is there any way to get form values other than by name ?? i tried and can not find an answer , please help .............
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在
name
属性中使用括号:这将允许 PHP 接受与值数组同名的多个输入,因此在本例中,
$_POST['hidden ']
将返回一个字符串数组。默认情况下,它们的索引从 0 开始,因此
$_POST['hidden'][0]
将为您提供第一个,$_POST['hidden'][1]
> 将为您提供第二个等,但是 - 如果您更容易的话,您可以使用数字或字符串显式索引它们。或者:
您可以将它们嵌套到您想要的深度,例如
hidden[first][1][]
,并且当您获取$_POST
时,它们将被视为类似于 PHP 数组code> 值,但您需要 HTML 中的括号。如果没有括号,
$_POST
数组中将只有最后一个字段的值可用。这是 PHP 的功能,Codeigniter 对此无能为力。You'll need to use brackets in your
name
attributes:This will allow PHP to accept multiple inputs with the same name as an array of values, so in this case,
$_POST['hidden']
will return an array of strings.By default they are indexed starting at 0, so
$_POST['hidden'][0]
will get you the first one,$_POST['hidden'][1]
will get you the second, etc., however - you can explicitly index them if it's easier for you, either with numbers or strings.Or:
You can nest these as deep as you want like
hidden[first][1][]
, and they will be treated similarly to a PHP array when you get the$_POST
values, but you need the brackets in the HTML.Without brackets, only the last field's value will be available in the
$_POST
array. This is a PHP feature, Codeigniter can't do anything about it.