I tried to create an activity log in Codeigniter based on changes in input made by the user and produce an output like this
Output : User1 Changes: Address (Street A) becomes (street B), date of birth (March 10, 2000) becomes (March 20, 2000), Phone number (0000) becomes (11111).
When I Submit my form, I can find out which data has changed, for example address, from address A to address B. I want store on database for Logs. I might have been able to enter the data into the database, but I still don't know how to get the output data, I have try with to use jQuery but not success. is there a function to do that in codeigniter?
This my input form.
<?php echo form_open(base_url('update_profile'), 'class="form-horizontal"'); ?>
<label for="address">Address:</label><br>
<input type="text" id="address" name="address" value="Street B"><br>
<input type="hidden" id="old_address" name="old_address" value="Street A"><br>
<label for="birth">Date Birth:</label><br>
<input type="text" id="birth" name="birth" value="March 20, 2000">
<input type="hidden" id="old_birth" name="old_birth" value="March 10, 2000">
<label for="phone">Phone number:</label><br>
<input type="text" id="phone" name="phone" value="11111">
<input type="hidden" id="old_phone" name="old_phone" value="0000">
<label for="email">Email:</label><br>
<input type="email" id="email" name="email">
<?php echo form_close(); ?>
My controller
public function update_profile(){
$is = $this->session->userdata('id');
$this->form_validation->set_rules('phone', 'Phone', 'trim');
if ($this->form_validation->run() == FALSE) {
$errors = validation_errors();
echo $errors;
}
else{
$data = array(
'address' => $this->input->post('address'),
'birth' => $this->input->post('birth'),
'phone' => $this->input->post('phone'),
'email' => $this->input->post('email'),
);
$data = $this->security->xss_clean($data);
$result = $this->data_user->update_model_profile($data, $id);
$result = true;
if ($result) {
echo $result;
}
}
}
and this my model.
public function update_model_profile($data, $id){
$this->db->where('user_id', $id);
$this->db->update('data_profile', $data);
return true;
}