May 13, 201511 yr Hello all, I'm designing a web page using CodeIgniter that allows the user to update their personal details. The form consists of three textfileds, this includes 'Password' 'Re-Type password' and an 'Upload new image'. I've designed these forms in the past, just not using an MVC. I'm using this line of code; $this->form_validation->set_rules('password', 'Password', 'required|callback_compare_password'); As you can see I'm calling a function called 'compare_password' that checks if the field matches the retype field'. This works fine. However, I want the user to be allowed to either just change their password and/or change the image. If I change the password then it updates the DB fine and if I change bot the password and image it also updates the DB fine but if I only change the image then it displays the error message informing the user to enter their password. This is fine but I want to display this error message only when the user enters their password. for example: if(empty($this->input->post('password'))) { ........upload image } else { ..............do something else the above line checks if the form field is empty and if so checks if the file is not empty then uploads new image and updates DB if both are not empty update both password and image and so on, there's only three permutations. What I'm wondering does CodeIgniter have a function that checks if a field is empty and if so ignores it. I've Googled around but can't find anything on it. If it doesn't I'll just have to use my own function to do the job.
June 2, 201511 yr i have use form validation following method on code igniter <?php class Form extends CI_Controller { function index() { $this->load->helper(array('form', 'url')); $this->load->library('form_validation'); if ($this->form_validation->run() == FALSE) { $this->load->view('myform'); } else { $this->load->view('formsuccess'); } } } ?>
Create an account or sign in to comment