douhuan7862 2017-07-21 12:07
浏览 59
已采纳

无法使用codeIgniter验证更改值

Here i have a list of contacts where user can add new contacts as well as edit them. Now at the add time i'm using server-side validation by codeIgniter for reduce redundancies. Also here i have a number of users that can add their contacts.

Suppose their are users named "John" and "Sara".

In this case, whenever "john" add new contact that are prevoiusly added by him, then it can't be add as duplicate contact number.

But whenever "john" add new contact that are previously added by "Sara", them it can be add . but its unable to add because CodeIgniter form_validation check unique value with entire table data.

Here is my Controller Code

 $this->form_validation->set_rules('customer_email','Email', 'trim|check_email[customer.customer_email.' .$userId. ']', array('check_email' => 'Email must be unique.'));
    $this->session->set_flashdata('check_email','Mobile must be unique');

            $this->form_validation->set_rules('customer_mobile', 'Mobile', 'required|is_unique[customer.customer_mobile]');
            $this->session->set_flashdata('contact_exists','Mobile must be unique');


    if ($this->form_validation->run()) {
        $userdata = $this->session->userdata();
        $userId = $userdata['id'];
        if (!$userId):
            redirect(site_url());
        endif;

I trying to many time but unable to fix this issue. I need your kind efforts. Thanks

  • 写回答

1条回答 默认 最新

  • dsfs64664 2017-07-21 12:21
    关注

    Please find below solution.

    First you need to remove unique check from customer_mobile.

    $this->form_validation->set_rules('customer_mobile', 'Mobile', 'trim|required');
    

    Once form_validation runs true then check customer_mobile with user in database and if it return row then return error else insert Contact.

    if ($this->form_validation->run() == TRUE) {
        // $check = Check here for customer_mobile with user in database
        if($check):
           return 'Contact already exist';
        else:
           // Insert Contact 
        endif;
    }
    

    Let me know if it not works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序