【问题标题】:How can I add to config'd Form_validation in CodeIgniter?如何在 CodeIgniter 中添加到 config'd Form_validation?
【发布时间】:2010-03-07 18:39:33
【问题描述】:

我的情况有点复杂。我想为我的 form_validation 创建 $config 规则,以便我的代码更干净,但问题出在:

        if( $this->input->post( 'usertype' ) == "new_user" )
        {
            $this->form_validation->set_rules('new_email', 'E-mail Address', 'required|valid_email' );
            $this->form_validation->set_rules('new_firstname', 'First Name', 'required' );
            $this->form_validation->set_rules('new_lastname', 'Last Name', 'required' );
            $this->form_validation->set_rules('new_password', 'Password', 'required|matches[password_conf]' );
            $this->form_validation->set_rules('password_conf', 'Password Confirmation', 'required' );
        } else {
            $this->form_validation->set_rules('login_email', 'Login E-mail Address', 'required|valid_email' );      
            $this->form_validation->set_rules('login_password', 'Login Password Address', 'required' );
        }

如果我有条件规则怎么办?

【问题讨论】:

    标签: codeigniter validation


    【解决方案1】:
    if( $this->input->post( 'usertype' ) == "new_user" )
    {
        if ($this->form_validation->run('booking_create_new_account') == TRUE)
        {
            // do stuff
        }
    }
    else 
    {
        if ($this->form_validation->run('booking_create') == TRUE)
        {
            // do stuff
        }
    }
    

    这会起作用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-06
      • 2015-08-07
      • 2015-10-06
      • 2012-09-30
      • 1970-01-01
      • 2011-11-14
      • 1970-01-01
      相关资源
      最近更新 更多