Validation Always Print Error Message |
Here is my Controller
Code: public function pagecreate() Here is my Views Code: <div class="row"> And issue is Views always print validation error message withour submiting form ? The title field is required. The body field is required. Is there any problems with my code ?
My guess is that it is because you are initiating Validation as a service in the view, so you are still getting the same instance (I.e. rules) but not the run result from the controller. Try passing $validation into the view directly and using that to display errors.
I had the same problem and thought it was its normal way of working while it checks if validation has passed and if not, shows the form. "If not" meaning there are errors. To solve this I added in my controller function
PHP Code: $data['isPost'] = $this->request->getMethod()=='post'; And then in the html where I show the errors Code: <?php if($isPost) echo service('validation')->listErrors() ?> That way only when the form is sent (if actually sent through post) will the errors show. If there is a better way, I'd be glad to hear it.
04-03-2019, 06:31 AM
(This post was last modified: 04-03-2019, 06:35 AM by elephpantech. Edit Reason: typo error )
My approach would be:
controller: PHP Code: public function pagecreate() views: PHP Code: //Backend/Themes/Base PHP Code: // Backend/Pages/Create
I think how @elephpantech (awesome handle) does it is in line with "intended" use (whatever that is worth). You can also check out @kilishan's implementation in Myth:Auth, with the caveat that some of that code is based on an older version of CI4: https://github.com/lonnieezell/myth-auth...er.php#L62
|
Welcome Guest, Not a member yet? Register Sign In |