为什么我的表单验证没有在codeigniter中设置

时间:2017-09-22 01:00:08

标签: php codeigniter

我试图用CI创建模板化系统。到目前为止,一切都运行良好,我正在测试表单验证,但它根本不工作。从下面的代码中可以看出,有html5必需的语句以及codeigniter规则。点击提交按钮后,两者都没有工作。所以我不确定什么是错的。有点愚蠢我肯定。

public function show_form(){



    $form_data = '<div class="row">
        <div class="col-md-12">
            <div class="card-box">
                <h4 class="m-t-0 header-title"><b>Basic Form Wizard</b></h4>

                <form id="basic-form" action="#">
                    <div>
                        <h3>Account</h3>
                        <section>
                            <div class="form-group clearfix">
                                <label class="col-lg-2 control-label " for="username">User name *</label>
                                <div class="col-lg-10">
                                    <input class="form-control" id="username" name="username" type="text">
                                </div>
                            </div>
                            <div class="form-group clearfix">
                                <label class="col-lg-2 control-label " for="password"> Password *</label>
                                <div class="col-lg-10">
                                    <input id="password" name="password" type="text" class="required form-control">

                                </div>
                            </div>

                            <div class="form-group clearfix">
                                <label class="col-lg-2 control-label " for="confirm">Confirm Password *</label>
                                <div class="col-lg-10">
                                    <input id="confirm" name="confirm" type="text" class="required form-control">
                                </div>
                            </div>

                        </section>


                        <input type="submit" value="Submit" />
                    </div>

                </form> 

            </div>
        </div>
    </div>';

    $this->CI->form_validation->set_rules('username', 'Username', 'required');

    if ( $this->CI->form_validation->run() == FALSE ):
        echo "<pre>Before Validation</pre>";
        echo validation_errors();
        echo "<pre>After Validation</pre>";
        echo $form_data;
    else:
        echo "We did it";
    endif;


}

提前感谢任何指导。

0 个答案:

没有答案