validation needs trim for repopulating?? |
[eluser]frenzal[/eluser]
I've discovered this weird validation issue: the repopulating doesnt work unlessI add trim to the rules as well. I found the solution by comparing to a form that did work, however I find this rather weird behaviour. Any idea why this won't work without trim Here's the code that doesnt work, tested on 1.61 and 1.5 something Code: function test(){ and my form with @ to supress the errors when first viewed Code: <?= form_open("admin/mothership/testpost"); ?> Bug, feature? Or am i missing something stupid here ![]()
[eluser]Tom Glover[/eluser]
I cant see anything wrong with this? so I don't no it may be a bug??
[eluser]Daniel Eriksson[/eluser]
You forgot to set_fields(). Something like this: Code: $fields['test'] = 'Test field'; Check the validation section of the User Guide for more information. If you do it the right way you can skip the @ also! /Daniel
[eluser]xwero[/eluser]
The required rules only trigger if there is no input so there will be no value if you repopulatethe field. Or is it the case if you add a value to one field but not to the other that the field with a value doesn't have a value when you repopulate the form?
[eluser]frenzal[/eluser]
$fields aren't required, but I tried adding them anyway and it makes no difference. And don't worry I've read the userguide plenty ![]() "Or is it the case if you add a value to one field but not to the other that the field with a value doesn’t have a value when you repopulate the form?" -> yep, and by adding a trim to my rules all is well again but I'd still like to get to the bottom of this
[eluser]Daniel Eriksson[/eluser]
[quote author="frenzal" date="1207504756"]$fields aren't required, but I tried adding them anyway and it makes no difference. And don't worry I've read the userguide plenty ![]() They ARE required for automatic repopulation. I suggest you re-read the user guide! /Daniel
[eluser]Pascal Kriete[/eluser]
Daniel E is right on the money. The reason why it works with trim is because of this line (305) in the Validation class: Code: $_POST[$field] = $rule($_POST[$field]); It repopulates the field for native php functions. The ci wrappers only set the POST, so you need to call set_fields seperately. I don't really understand the design choice here, but regardless, the user guide is quite clear on this in the Re-populating the form section.
[eluser]frenzal[/eluser]
[quote author="Daniel E" date="1207506419"][quote author="frenzal" date="1207504756"]$fields aren't required, but I tried adding them anyway and it makes no difference. And don't worry I've read the userguide plenty ![]() They ARE required for automatic repopulation. I suggest you re-read the user guide! /Daniel[/quote] wow, i feel so stupid I can't believe I missed that thanks for clearing that up |
Welcome Guest, Not a member yet? Register Sign In |