When I try to populate a form field which is not required in form validation doesn't repopulate. Let's say I have a field but I don't want it to be required but I want it to be repopulated. How can I do it ? I think this is a bug for codeigniter.
4
votes
What do you mean by repopulated? Do you mean you want to set the value of a field after a from is submitted but not valid?
- Matthew Rapati
I want to repopulate a field which is not set as required in form validation rules. In form validation if you don't set a rule as required It doesn't populate it.
- SNaRe
BTW; I think I solved the problem with a hack with helpers. But I'm really wondering a real solution.
- SNaRe
3 Answers
4
votes
3
votes
You have to set a validation rule on a field in order for it to repopulate on an invalid submission. Luckily, you can pass regular PHP functions, not just validation rules, to the set_rules() method so you could just set trim or something rather than required.
$this->form_validation->set_rules('your_field', 'Your Label', 'trim');
That will repopulate the field and not make it a required field.