Form value repopulate |
For a form I am working on I am trying to repopulate the fields after a submit and validation detected issues.
No matter what I try, it does not seem to work. My controller looks like this: Code: public function index() The view looks like this: Code: $attributes = ['class' => 'needs-validation', 'id' => 'form']; If I look at the examples in de docs this should be sufficient to repopulate a form but it stays blank. Any ideas? In the manual for CI 4 there is no mention of the repopulate option anymore under the validation library but I see the options are now listed under the forms section. Even in the examples there is no mention of this option, nor is it under the upgrade page (Upgrade Validations — CodeIgniter 4.1.9 documentation). Is this ommited or does it need to be implemented in a different way? I would be noteworthy to mention this on a upgrade page. (05-24-2022, 11:49 PM)vinyl Wrote: For a form I am working on I am trying to repopulate the fields after a submit and validation detected issues. have you tried PHP Code: value="<?= old('email') ?>" give it a shot and lemme know
to use this [ value="<?= old('email') ?>" ] , you need return like this [ withInput() ]:
return redirect()->back()->withInput()->
CodeIgniter 4 User Guide - Global Functions and Constants - old
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Why do the form helper documentation or those of validation not mention this?
So instead of using: Code: echo view('form', [ I need to do a redirect? Coming from CI3 this would have never crossed my mind, especially since the docs don't mention it anymore. Thanks all for the help.
Your code works as expected.
PHP Code: <?php PHP Code: <?php
Well, I have exactly what you posted and my form is not returning values.
About this: Code: return redirect()->back()->withInput()-> The documentation says: Quote:If you are using the form helper, this feature is built-in. You only need to use this function when not using the form helper. But set_value and old are both not working. Im writing because I had the same problem.
Solution for me: 1. In controller Code: function __construct() Code: value="<?php echo set_value('[your field]'); ?>" |
Welcome Guest, Not a member yet? Register Sign In |