![]() |
Update email only if the email doesn't exist in the database - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Update email only if the email doesn't exist in the database (/showthread.php?tid=1374) |
Update email only if the email doesn't exist in the database - Taylor - 03-04-2015 I have an update page for my users where they can edit their name, email and other info. So far, they can edit everything. Including their email. They can enter an email that already exists in the database without any issue. I have tried adding this form validation rule PHP Code: $this->form_validation->set_rules('email', 'Email', 'trim|required|xss_clean|is_unique[users.email]'); I just want to make it so that when they click the save button, only update the email if the user has changed it AND check that the email doesn't exist in the database before saving. I have tried doing this but no luck. The code that I'm playing with: PHP Code: $first_name = $this->input->post('first_name'); RE: Update email only if the email doesn't exist in the database - silentium - 03-04-2015 Add a hidden form field named 'original_email' and set the value to the users email. This field will be used as reference to detect if the users has changed the email when saving. In the form validation PHP code we only add the unique form validation if needed. PHP Code: // We do the unique check only if the email field to not match the original email |