doujiaozhan2413 2015-12-19 21:43
浏览 22
已采纳

CI表单验证

I'm developing a function that should enable users to update their personal information and I'm using CI form validation library. I'd want to know if what I'm doing is right.

public function updateDetails()
{
    $this->load->model('users_model'); // load users model

    $username = $this->input->post("username", true); // get the post from view

    $this->form_validation->set_rules('username', 'Username', 'required|max_length[32]');

    if($this->form_validation->run() === true)
    {
        // Send to model
    }

}

Is this right? Or is there another method to do this?

  • 写回答

1条回答 默认 最新

  • doumenshi1475 2015-12-19 22:38
    关注

    yes so far you're right but you should process if the validation is successful

    public function updateDetails()
    {
        // load the library if not already loaded in config/autoload.php
        $this->load->library('form_validation');
    
        $this->form_validation->set_rules('username', 'Username', 'required|max_length[32]');
    
        if($this->form_validation->run() === true)
        {
            $this->load->model('users_model'); // load users model
            $username = $this->input->post("username", true); // get the post from view
            // Send to model
        }
        else
        {
            $data['error_message'] = "form not valid ...blablabla";
    
            //go back to form
            $this->load->view("form_vew",$data);
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号