doulun0651 2016-09-28 11:37
浏览 62

Codeigniter表单验证

Here is my controller

  function register(){
        $_POST['username'] = $_GET['username'];
                $this->load->library('form_validation');
                $this->load->helper('form');
        $this->form_validation->set_rules('username', 'username', 'required|trim|xss_clean|min_length[5]');
        if($this->form_validation->run())
        {

        }
        var_dump(form_error('username'));
}

Can I test this funtion with home/register?username=test ??? I tried but it not working

  • 写回答

1条回答 默认 最新

  • douan6931 2016-09-28 15:40
    关注

    Well, apart from you question being a bit confusing, I think the answer is no. You cannot test a post request with a get request from url parameters.

    The way to test a post request is to post the required test data.

    I am pretty sure that is correct, however, as I said your question was a bit confusing so if I am missing your point, I apologize in advance.

    If you want to test validation NOT from a post, you can use the validation rules on any array.

    $data = array(
        'username' => 'johndoe',
        'password' => 'mypassword',
        'passconf' => 'mypassword'
    );
    
    $this->form_validation->set_data($data);
    

    You can read more about that here: http://www.codeigniter.com/user_guide/libraries/form_validation.html#validating-an-array-other-than-post

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?