Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 表单验证后重新格式化POST数据的Codeigniter_Php_Forms_Codeigniter - Fatal编程技术网

Php 表单验证后重新格式化POST数据的Codeigniter

Php 表单验证后重新格式化POST数据的Codeigniter,php,forms,codeigniter,Php,Forms,Codeigniter,我有一个问题,我无法想象这是怎么回事。因此,我运行form_验证来验证我的表单输入。在此之后,$\u POST['user\u name']变成数组而不是字符串 $this->form_validation->set_rules('user_name', 'Vartotojo vardas', 'trim|required|min_length[5]|max_length[30]|alpha_dash|callback_checkUserNameUnique');

我有一个问题,我无法想象这是怎么回事。因此,我运行form_验证来验证我的表单输入。在此之后,
$\u POST['user\u name']
变成数组而不是字符串

$this->form_validation->set_rules('user_name', 'Vartotojo vardas',
        'trim|required|min_length[5]|max_length[30]|alpha_dash|callback_checkUserNameUnique');
    $this->form_validation->set_rules('email', 'El. pašto adresas',
        'trim|required|valid_email|callback_checkEmailUnique');
    $this->form_validation->set_rules('password', 'Slaptažodis',
        'trim|required|min_length[5]|max_length[60]');
    $this->form_validation->set_rules('password_2', 'Slaptažodžio pakartojimas',
        'trim|required|min_length[5]|max_length[60]|matches[password]');
    $this->form_validation->set_rules('phone_number', 'Telefono numeris',
        'trim|required|callback_checkIfPhoneGood');

    $this->setFormMessages();


    if ( $this->form_validation->run() == false ) {
        $data['json'] = array(
            'failed' => true,
            'errors' => $this->form_validation->error_array()
        );
    } else {
        print_r($_POST['user_name']);
        print_r($this->input->post('user_name', true));
    }
在启动
$this->form\u validation->run()
和打印
$\u POST['user\u name']
之前,它返回字符串;在
$this->form\u validation->run()之后,它返回空数组

有什么想法吗

编辑:

我的CheckUserName唯一方法:

function checkUserNameUnique($userName)
{
    return $this->cache->model('system_model', '_getCustomTableData', array(
        'users', array(array('user_name' => strtolower($userName))), 'id DESC', FALSE, 1
    ), CACHE_USER_CHECK_INFO_TIME);
}

\u getCustomTableData
返回一个数组,因此如下更改回调函数:

function checkUserNameUnique($userName)
{
    if (empty($this->cache->model('system_model', '_getCustomTableData', array(
        'users', array(array('user_name' => strtolower($userName))), 'id DESC', FALSE, 1
        ), CACHE_USER_CHECK_INFO_TIME)))
    {
        return TRUE;
    }
    else
    {
        $this->form_validation->set_message('username_unique', 'The %s field must be unique.');
        return FALSE;
    }    
}
表单验证还支持检查唯一性:

$this->form_validation->set_rules('user_name', 'Vartotojo vardas',
    'trim|required|min_length[5]|max_length[30]|alpha_dash|is_unique[users.user_name]');

可能是您的回调检查UsernameUnique导致了这些问题?你试过把这个拿走吗?天哪,谢谢。但我不知道为什么会有问题。添加了函数代码。我们首先删除
| callback_checkUserNameUnique
,然后确定这是否是您的问题。否则,这个函数正在调用另一个模型,所以我仍然不知道它在做什么。@Devon是的,出现了一个问题。但我不明白为什么,只有一个回叫检查。感谢您的帮助,更改了方法操作,问题消失了。无论是否回调,所有规则都可能以两种方式之一进行操作-验证或修改。如果函数/规则返回布尔值,则验证;在任何其他情况下,它都会修改原始输入,
trim
也是这样工作的。