CodeIgniter Forums
How do I show form fields after validation fails? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How do I show form fields after validation fails? (/showthread.php?tid=7384)



How do I show form fields after validation fails? - El Forum - 04-07-2008

[eluser]The Mask[/eluser]
Hi,
I am using the validation class on certain fields which is working fine.
However, on the fields that require no validation (e.g. Forename), how do I show the entered value on the form if the validation fails on other fields?
Thanks
Neil


How do I show form fields after validation fails? - El Forum - 04-07-2008

[eluser]Crimp[/eluser]
See the CI user guide for the Validation class. You put this in your HTML value: $this->validation->[name of field];


How do I show form fields after validation fails? - El Forum - 04-07-2008

[eluser]webthink[/eluser]
Crimp I think you may have misread the question. The OP needs to know how to repopulate fields with *no* validation.
The simple answer is to put it in your fields and validation array without actually attaching any rules to it.

In our apps we tend to have a $defaults array that gets populated any number of ways.
1. from scratch - no validation has occurred the form is just empty... $defaults gets populated with '' or 0 depending on the type of field
2. from db - this is for initial display of forms meant to update a record... $defaults gets populated with fields from the db.
3. from post - after failed validation $defaults gets populated with fields from the post.


How do I show form fields after validation fails? - El Forum - 04-07-2008

[eluser]The Mask[/eluser]
Thanks for the replies.
It crossed my mind that I may have to set up dummy rules and then populate from $_POST but thought there may have been an easier way.
Many thanks