Create multiple subclasses of Form Validation + callback inside should work |
This is a two-part problem because I believe the issues are dependent on each other.
What I want to achieve: I am creating a site with multiple specific forms and I want each of them to have their (1) own validation class instead of a bloated MY_Form_validation.php. (2) Callbacks will also happen inside that validation class and not within the form's controller. OK CASE: I create MY_Form_validation.php with a callback method called "check_value": PHP Code: <?php check_value is called inside validate() and it is called without the "callback_" prefix. It works that way. This validation class is used in the form controller as: PHP Code: public function __construct() and the method called: PHP Code: $this->form_validation->validate(); NOK CASE: Same settings with OK CASE, just with a classname like "Car_registration_form_validation" and the manner of usage: PHP Code: public function __construct() PHP Code: $this->car_registration_form_validation->validate(); With the settings above, I get the following error: Code: Unable to access an error message corresponding to your field name my_field.(check_value) My questions:
I can probably guess your answer, but could you explain what would "bloat" MY_Form_validation.php ?
(09-05-2016, 09:21 AM)dave friend Wrote: I can probably guess your answer, but could you explain what would "bloat" MY_Form_validation.php ? I have five to ten forms each with unique validations. I can put all their respective business logic inside MY_Form_validation but I do not like having a long and fragile class. I would just like each of these unique forms to have their own form validation subclass. Please share what to do to fix this especially the dependency on the native callback calling. |
Welcome Guest, Not a member yet? Register Sign In |