Welcome Guest, Not a member yet? Register   Sign In
Cheap Form Validation Trick
#1

[eluser]cwt137[/eluser]
When you do form validation, and an error occurs, when the form gets re-populated, the fields without form validation rules do not get re-populated. This bug is very annoying. I found a cheap way around this problem until this problem is fixed. My solution is for the fields that don't require validation, still make a rule for it like so:

Code:
$this->form_validation->set_rules('foo_field','', 'callback__not_required');

Then in the call back function, just return true:

Code:
function _not_required($str) {
  return TRUE;
}

This way if some other field does not pass validation, the field that I don't need validated will still get re-populated.
#2

[eluser]Thorpe Obazee[/eluser]
or you can use 'trim' on all your form inputs.
#3

[eluser]Phil Sturgeon[/eluser]
Or even an empty string for the rule.
#4

[eluser]cwt137[/eluser]
Thanks. I think I'll use the empty string for the rule.
#5

[eluser]Colin Williams[/eluser]
I don't think it's a bug, but it's kind of a weakness brought on by the limited scope of the Form Validation class. It also kind of depends on how you go about repopulating your form fields.
#6

[eluser]Thorpe Obazee[/eluser]
[quote author="Phil Sturgeon" date="1239123775"]Or even an empty string for the rule.[/quote]
lol. forgot about that :p




Theme © iAndrew 2016 - Forum software by © MyBB