![]() |
Form Validation "dot array" - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Form Validation "dot array" (/showthread.php?tid=80880) |
Form Validation "dot array" - Kor - 12-28-2021 Greetings. Maybe or maybe not, this thread has been submitted. I have done a research and unfortunately I have not found any answer about it. I'm developing my fist CI-4 project. I use CI since 1.5 version and never regretted. Until very recently I was resisting to let CI-3 go, because I was quite comfortable with this version, but that would be counter productive. Things always move forward. It has not being easy, especially because I have found CI-4 documentation not quite simple and straight forward as it used to be, as also not quite thorough. Anyways, I'm having some throuble with form validation. I have this html form which has dynamic inputs that are array named, like 'addresses[X][country] ' where 'X' is the index. I have created the rules for this 'country' input and it is validating just fine. The problem is that I show individual error messages for each input and the message is being shown in those inputs that are filled with data. To make it clear, I'll post some sample code below: Code: public $customers = [ Code: $this->form_validation->reset(); Here the rules are applied. Code: Array This is what getErrors() returns, which are the messages for the inputs. So far so good. Now it comes the throuble. Code: <div class="col-md-4"> Country is cloned and inserted in the form dynamically. So, I can have many country inputs and not all will be filled. Those who are not filled, should exhibit the error message, but only the empty ones. The problem is that those that are filled, are also showing the error message. I hope it is clear enough. If not, just ask me. So... Any thoughts? Thanks for listening. RE: Form Validation "dot array" - kenjis - 01-02-2022 If you have 'addresses[X][country] ' where 'X' is the index, it seems the validation rule 'addresses.country' should be 'addresses.*.country'. https://codeigniter.com/user_guide/libraries/validation.html#validating-keys-that-are-arrays RE: Form Validation "dot array" - iRedds - 01-02-2022 (01-02-2022, 01:48 AM)kenjis Wrote: If you have 'addresses[X][country] ' where 'X' is the index, I understand what this is about. PHP Code: $data = [ 1. In fact, there are two errors, but one (the last) is displayed. Because the $field parameter is used for the error key. 2. It is impossible to determine which specific field the error applies to. The error format should be like this PHP Code: $erros = [ RE: Form Validation "dot array" - kenjis - 01-02-2022 > Because the $field parameter is used for the error key. Do you mean overwriting the error message by the latter error? Anyway, it seems there is no way to get more than one error messages. We have to say it is a bug. RE: Form Validation "dot array" - iRedds - 01-02-2022 Yes, the error message is being overwritten because of the same key. |