![]() |
Do you know withInput() and Validation errors? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31) +--- Thread: Do you know withInput() and Validation errors? (/showthread.php?tid=82735) |
Do you know withInput() and Validation errors? - kenjis - 08-16-2022 redirect()->withInput() and Validation errors have an undocumented behavior. If you redirect with withInput(): PHP Code: if (! $this->validate($rules)) { You can use the Validation object with the validation errors in the previous page. PHP Code: <?= service('Validation')->listErrors() ?> But this feature has bugs or design flaw. So I would like to remove the feature, and add a new helper function to get the validation errors. Any opinion? RE: Do you know withInput() and Validation errors? - luckmoshy - 08-16-2022 Yes even I was been asking myself such a thing but I neglected to pursue a query !!! ??? RE: Do you know withInput() and Validation errors? - InsiteFX - 08-17-2022 Sounds great to me. RE: Do you know withInput() and Validation errors? - kenjis - 08-17-2022 @luckmoshy What do you mean? Have you ever used the feature? RE: Do you know withInput() and Validation errors? - luckmoshy - 08-17-2022 @kenjis of cause at earlier from CI 4.0 I didn't know what to do with redirect withinput back and get a specific error because of CI documentation The global return PHP Code: redirect()->back()->withInput(); PHP Code: <?= service('Validation')->listErrors() ?> ![]() ![]() @kenjis I truly have been using this global CI PHP Code: redirect()->back()->withInput(); PHP Code: redirect()->back()->withInput()->with('danger/*success*/',/*In modal*/$this->modal->errors() /*or something else apart with modal */); PHP Code: session()->get('danger/*success*/'); / but I may have a view of the point that it could be good if you design a new helper function and may have a specific single error validation result perimeter or with multiple validations on its parameter something like that or this PHP Code: redirect()->back()->withInput(); in additionally, Why this PHP Code: redirect()->back()->withInput(); Code: routes priority PHP Code: redirect()->to(current_url())->withInput(); RE: Do you know withInput() and Validation errors? - kenjis - 08-31-2022 The undocumented redirect()->withInput() and Validation errors behavior was treated as a bug. It won't work, so do not use it. Since v4.3, you can use Form helper validation_list_errors() (and validation_errors(), validation_show_error()). See https://github.com/kenjis/ci4-validation-tutorial/blob/21e3c0811eb32540da8f706a9312641dd3e42e73/app/Views/form2.php#L7 RE: Do you know withInput() and Validation errors? - kenjis - 10-16-2022 Added explanation to README. https://github.com/kenjis/ci4-validation-tutorial#readme RE: Do you know withInput() and Validation errors? - InsiteFX - 10-17-2022 Thank you @kenjis |