Throw Exception, Validation and Error Handling |
Struggling here. I have a form with validation. I have a custom rule with a callback method. In the callback method, I have a try/catch exception on a google lib that has a good number of custom validation messages eg, not a valid phone number, phone number too long, etc). How can I validate the form and also get back the custom message
PHP Code: // validates the phone number. takes a phone number and a country code. in the teleNumberValidation i want to do something like this; Code: try { but validation only accepts true or false so how can I get $e->getMessage() into something like this; Code: return redirect()->back()
(04-04-2022, 10:16 PM)kenjis Wrote: See https://codeigniter4.github.io/userguide...stom-rules Hi Kenjis, thank you for the link. I have read through it but not sure still how I would return the exception error message. If you could kindly let me know a bit more. I have tried to dig through other projects like bonfire 2 to try to find how it is done but I am also finding it hard to get an example.
Something like this:
PHP Code: public function teleNumberValidation( See also https://codeigniter4.github.io/userguide...parameters
Thank you Kenjis.
Almost clear. I don’t understand the need to pass in &$error in my case. Also, no need to return $error. I am also not clear on references but am reading about them still. Thanks!
See https://www.php.net/manual/en/language.r...s.pass.php
The validation method must return boolean. So it can't return error strings. So we use Passing by Reference.
|
Welcome Guest, Not a member yet? Register Sign In |