1

validation error is not showing. This is my update function.

public function index_put($id)
{
    try
    {
        $input = $this->put();
        if($input)
        {
            $this->form_validation_update();
            if($this->form_validation->run() == FALSE)
            {
                $this->error_msg();
            }
            else
            {
                if($this->db->update('admins', array('id'=>$id))){
                    $this->update_msg();
                }
                else{
                    throw new Exception("The Data Already Register or The Data is Empty");
                }
            }
        }
    }
    catch (Exception $e)
    {
       $error = array($e->getmessage());
       $errormsg = json_encode($error);
       echo $errormsg;
    }

}

and now this is my validation query function:

public function form_validation_update()
{
    $this->form_validation->set_rules('fname','First Name','trim|required|max_length[128]|xss_clean|alpha');
    $this->form_validation->set_rules('lname','Last Name','trim|required|max_length[128]|xss_clean|alpha');
    $this->form_validation->set_rules('email','Email','trim|required|valid_email|xss_clean|max_length[128]');
    $this->form_validation->set_rules('username','User Name','trim|required|max_length[128]|xss_clean');
    $this->form_validation->set_rules('phone_no','Phone Number','required|min_length[6]|xss_clean|numeric');
    $this->form_validation->set_rules('role_id','Role','trim|required|numeric');
    $this->form_validation->set_rules('address_line_1','Address','required|xss_clean');
}

and now this is error message showing function for update query.

public function error_msg()
{
        $error = $this->form_validation->error_array();
        $errormsg = array(
                        'code' => 6, 
                        'msg' => 'Details provided are not valid. Please enter valid details.', 
                        'data'=> array('validation_errors' => $error)
                    );
        echo(json_encode($errormsg));
        echo '<pre>';
        print_r($error);
        die();
}

and this output is

{"code":6,"msg":"Details provided are not valid. Please enter valid details.","data":{"validation_errors":[]}}

update function is called but not giving data of form validation. and i also what validation for unique check email is already register or not but not in that id when data is updating

2 Answers 2

1

By default form validation library uses $_POST to validate input data. To validate Put request data, you manually need to pass put data to the library before running validation.

$this->form_validation->set_data($input);
Sign up to request clarification or add additional context in comments.

Comments

0

And Last I Tried This And It's Working Perfectly

if ($this->CI->input->method() !== 'post' && empty($this->validation_data))
    {
        return $this;
    }

To,

if ($this->CI->input->method() !== 'post' && $this->CI->input->method() !== 'put' && empty($this->validation_data))
    {
        return $this;
    }

In Form Validation Library File Because I request Through put and i have to assign put in the method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.