使用form_validation库验证代码Igniter中的多维数组 [英] Validating multidimensional arrays in Code Igniter with form_validation library
问题描述
我有一个奇怪的问题与代码igniter的form_validation模块。我试图验证多维数组从表单post,但它不能正常工作。我已经使用这一百次(夸张)与标准的表格帖,所以我熟悉它。
I'm having a weird problem with the form_validation module of code igniter. I'm trying to validate multi dimensional arrays from the form post, but its not working as expected. I've used this a hundred times (exaggeration) with standard form posts so I'm familiar with it.
我的表单职位看起来像这样
My form post looks like this
Array
(
[location_edit_id] =>
[theImage] =>
[thePDF] =>
[loc] => Array
(
[name] =>
[content_1] =>
[content_2] =>
[opening_hours] =>
[seats] =>
)
[ad] => Array
(
[address_1] =>
[address_2] =>
[address_3] =>
[town_city] =>
[county_id] =>
[region_id] =>
[postcode] =>
[telephone] =>
[email] =>
)
)
文档 - 我的控制器中的操作需要看起来像这样,如果我想验证$ _POST ['loc'] ['name']
According to the docs - the action in my controller needs to look like this if I want to validate the $_POST['loc']['name']
$this->validation->set_rules( 'loc[name]', 'Location Name', 'required');
if ($this->validation->run() == FALSE)
{
die( "did not validate" );
}
else
{
die( "validated" );
}
无论我做什么,这总是验证,即使$ _POST ['loc '] ['name']为空。我已经检查了库文件库/ Validation.php,我看不到任何地方这实际上可以工作(因为它总是只是寻找变量名匹配 - 不是数组),所以我不知道发生了什么。
no matter what I do, this always validates even if $_POST['loc']['name'] is empty. I've examined the library file libraries/Validation.php and I cant see anywhere where this would actually work (as its always just looking for variable name matches - not arrays), so I'm not sure whats going on.
编辑:我使用的代码点火器版本1.7.2这是最新的稳定版本。
I'm using Code igniter version 1.7.2 which is the latest stable release.
推荐答案
看起来您使用的库不正确。验证库已弃用。尝试改用Form_validation(libraries / form_validation.php)。
It looks like you're using the wrong library. The Validation library is deprecated. Try using Form_validation (libraries/form_validation.php) instead.
$this->load->library('form_validation');
$this->form_validation->set_rules( 'loc[name]', 'Location Name', 'required');
if ($this->form_validation->run() == FALSE)
{
die( "did not validate" );
}
else
{
die( "validated" );
}
这篇关于使用form_validation库验证代码Igniter中的多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!