验证在Codeigniter中不起作用 [英] Validation is not working in codeigniter

查看:69
本文介绍了验证在Codeigniter中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

验证无效。所有表单字段都是动态变化的。这取决于用户选择多少字段。如果他选择2,它将在视图中显示2个字段。如果选择3,它将显示3个字段,依此类推。我有30多个字段

Validation is not working. All the form fields are coming dynamically. It depends on the user how many fields he chooses.If he chooses 2 and it will display 2 fields in the view. If select 3 then it will display 3 fields and so on.I have more than 30 fields

我设置了3个数组(出于测试目的,我只设置了3个数组。表单验证页中的字段总数)。如果我删除了最后一个数组,则验证工作,因为我在视图中仅得到2个字段。我无法在表单验证页面中使用2个以上的数组。

I set 3 arrays(for testing purpose I set only 3. It will be total no of fields ) in my form validation page. If I remove the last array than validation is working because I am getting only 2 fields in the view. I am not able to use the more than 2 array in my form validation page.

是否强制要求视图中的字段数等于集合数表单验证中的规则数组?

Is it mandatory to require the number of fields in view is equal to a number of sets of rules array in form validation?

查看

这是我的动态视图页面

<?php
   echo form_open('formbuilder_control/enxample_from_view');
    foreach ($data as $key) {// I am getting output
     $exp_fields_name=$key->fields_name;
     $exp_fields_type=$key->fields_type;
     $exp_form_elements=$key->form_elements;

    $abc=explode(',',$exp_form_elements);
        foreach ($abc as $value) {
          if ($exp_fields_name == $value) {?>
          <div class="form-group row label-capitals">
                  <label class="col-sm-5 col-form-label"><?php echo $exp_fields_name;?></label>
                  <div class="col-sm-7">
                  <input type="<?php echo $exp_fields_type;?>" name="<?php echo $exp_fields_name;?>" placeholder="<?php echo $value;?>" class="form-control" />
                   <?php echo form_error($exp_fields_name); ?>
                </div>
                </div>
                  <?php 
           }}}?>

              <div class="form-buttons-w btn_strip">
                <input type="submit" name="submit" value="Save" class="btn btn-primary margin-10">
              </div>

    <?php echo form_close(); ?>

Form_validation.php

$config = array(
    'test'=>array(

     array('field' =>'firstname', 
           'label' => 'First Name',
            'rules' => 'required'
    ),
        array('field' => 'lastname',
              'label' => 'lastname',
              'rules' => 'required'
              ),

     array('field' => 'middlename',
           'label' => 'middlename',
           'rules' => 'required'
         )
     ),
);

控制器

public function test()
{

        if($this->form_validation->run('test') == TRUE) 
        {
                echo "working";
        }
$this->load->view('test1');
}


推荐答案

当然,它将失败。您的验证规则将字段定义为必需,并且该字段甚至不存在于表单中。

Of course it will fail. Your validation rules define a 'middlename' field as required, and that field doesn't even exist in the form.

缺少字段不能满足必需的规则。

A missing field cannot satisfy a required rule.

这篇关于验证在Codeigniter中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆