Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.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 codeigniter中的自定义表单验证不工作_Php_Forms_Codeigniter_Validation - Fatal编程技术网

Php codeigniter中的自定义表单验证不工作

Php codeigniter中的自定义表单验证不工作,php,forms,codeigniter,validation,Php,Forms,Codeigniter,Validation,我有一个页面,上面有一些验证检查 $this->form_validation->set_rules('category', 'categorie', 'required_fr'); $this->form_validation->set_rules('description', 'omschrijving', 'required'); 我的form_validation_lang.php文件如下所示: $lang['required'] = 'Error messag

我有一个页面,上面有一些验证检查

$this->form_validation->set_rules('category', 'categorie', 'required_fr');
$this->form_validation->set_rules('description', 'omschrijving', 'required');
我的form_validation_lang.php文件如下所示:

$lang['required'] = 'Error message 1';
$lang['required_fr'] = 'Error message 2';
必需的是一个标准值,我添加了必需的\u fr。如果两个验证检查都失败,我只会得到“错误消息1”。第二次检查(必需的检查)不起作用

如果我在form\u validation\u lang.php文件中编辑“required”值,那么当form validation失败时,错误消息也会更改。但是“required_fr”值显然无法加载

我也试过把

$this->form_validation->set_message('required_fr', 'Error Message 2');
在我看来,但它也不起作用。 解决方案可能很简单,但我想我忽略了一些东西

我的页面的重要部分如下所示

<?php echo validation_errors(); ?>

        <div class="form-group">
            <label for="ticketCategory" class="col-sm-2 control-label"><?php echo ($this->session->userdata('franstalig') == 0) ? "Categorie" : "Catégorie" ?></label>
            <div class="col-sm-6">
                <select class="form-control" id="ticketCategory" name="category">
                    <option value="">Gelieve een categorie te selecteren</option>
                    <?php if (isset($categories) && !empty($categories)): ?>
                        <?php foreach ($categories as $category): ?>
                            <option value="<?php echo $category['id'] ?>" <?php echo set_select('category', $category['id']); ?>><?php echo $category['description']; ?></option>
                        <?php endforeach; ?>
                    <?php endif; ?>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label for="ticketDesc" class="col-sm-2 control-label">Omschrijving</label>
            <div class="col-sm-6">
                <textarea name="description" id="ticketDesc" class="form-control" rows="16"><?php echo set_value('description'); ?></textarea>
            </div>
        </div>

格丽芙·伊恩是一个有选择的人
另一种方式

尝试更改:

$this->form_validation->set_rules('category', 'categorie', 'required_fr');
$this->lang->load('form_validation_lang');
$this->form_validation->set_rules('category', 'categorie', 'required', array('required' => $this->lang->line('required_fr')));
至:

$this->form_validation->set_rules('category', 'categorie', 'required_fr');
$this->lang->load('form_validation_lang');
$this->form_validation->set_rules('category', 'categorie', 'required', array('required' => $this->lang->line('required_fr')));

我解决了这个问题。我补充说

public function required_fr($str) 
{
    if ( ! is_array($str))
    {
        return (trim($str) == '') ? FALSE : TRUE;
    }
    else
    {
        return ( ! empty($str));
    }
} 
调用
$this->form_validation->set_rules('category'、'category'、'callback_required_fr')
这就成功了。

然后我得到了:Message:Undefined variable:language更新了我的答案。我编辑了,但仍然不起作用。我已经没有错误了,但是validation\u errors()仍然返回“Error message 1”,它链接到
form\u validation\u lang.php中的“required”。php
$lang['required\u fr']
仍然设置为
'Error message 2'
?是。它只显示错误消息1,该消息链接到“required”。虽然我已经替换了
$this->lang->load('form_validation_lang')使用
$this->lang->load('form_validation')。如果我编辑错误消息1,则更改将应用于我的应用程序。您是否加载了语言文件。我现在加载了,但它仍然不起作用。如果调用“required\u fr”,则validation\u errors()不会显示错误。