![]() |
Form Validation - Callback to a Model? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=11) +--- Thread: Form Validation - Callback to a Model? (/showthread.php?tid=69935) |
Form Validation - Callback to a Model? - minsk832 - 02-01-2018 Hello, my User_model have a public method called is_unique_email($email). This method checks if a user has a uniqe mail adress with some status flag checks. This is also the reason why I can't use the standard is_unique validation rule from CodeIgniter. I'm using a form_validation.php with config array for my validation rule groups. My question ist: How can I call the model method for checking the new users e-mail adress? I searched and tried so many things, but nothing work. My preferred call would be with | pipe separator. Like: trim|required|max_length[70]|valid_email|<~ here comes the model callback ~> Is there any solution for this callback or is there no way and I have to extend the Form_validation system library? Thanks in advance! RE: Form Validation - Callback to a Model? - Zeff - 02-01-2018 (02-01-2018, 12:56 AM)minsk832 Wrote: Hello, Hi Minsk832, I've you're trying to shift form_validation to the model (I was inspired by Lonnie Ezell's MY_Model), maybe you're struggling with the same issue as I had: check 'use-thing-as-a-rule' and check proper formatting (see https://forum.codeigniter.com/thread-69930.html). You should update the validation method in your model to something like this: PHP Code: function is_unique_email($email) Good luck! Zeff RE: Form Validation - Callback to a Model? - minsk832 - 02-01-2018 Hello Zeff, at the moment I extend the CI_Form_validation which make it possible to access the is_unique_email method: PHP Code: <?php defined('BASEPATH') OR exit('No direct script access allowed'); form_validation.php: PHP Code: <?php But I don't unterstand how I can call model method from this rule config array directly. RE: Form Validation - Callback to a Model? - Narf - 02-01-2018 You can't. |