Welcome Guest, Not a member yet? Register   Sign In
Handling of typos in form validation rules
#1

[eluser]voidstar[/eluser]
Hello,

I just completed my first CI project, and I'm very pleased with the result. CI is great! Its structure and built-in facilities were very helpful!

One of the facilities that I used was Form Validation, and although it generally worked very well, I found one anomaly: invalid rules are ignored. For example in the following rule fragment "exact_length" is misspelled.

array(
'field' => 'yyyy',
'label' => 'Year',
'rules' => 'trim|required|exact_lngth[4]|is_natural_no_zero|callback__yyyy_check'
)

Form validation apparently ignores rules that it doesn't recognize. I don't know whether this is a feature or a bug, but if it is a feature, it should be documented.

I found post about a closely related problem, i.e. a misspelled callback function, here.
http://ellislab.com/forums/viewthread/92501/
#2

[eluser]xwero[/eluser]
It's a feature. Checking for typos in the rule name slows down the validation process which isn't a feature i would recommend Smile
#3

[eluser]helmutbjorg[/eluser]
Feature? It wouldn't be hard to do a simple function_exists and alert the user if it fails though? I think the benefit of being notified of a potential problem would outweigh the performance hit...
#4

[eluser]xwero[/eluser]
It's not really a feature but what is the use of knowing there is a typo in the rule name? You could log it on debug level but if you create a test and a rule isn't working as you expect you will discover the typo more clearly than having to browser trough a log file to discover you made a typo.

The reason you write tests is to prevent adding debuging code to classes.
#5

[eluser]helmutbjorg[/eluser]
I understand and can see where you are coming from... I look at it this way. PHP would simply alert me if i accidently wrote trum() instead of trim()... this codeigniter class doesn't. I think this sort of thing is a basic warning not really bloated debugging code and should be included.
#6

[eluser]xwero[/eluser]
I can see where your coming from too and i just checked the code, finding out it's not that hard to implement what you are asking because the method check is already added but instead of stopping to warn you it just moves to the following rule. check the from-validation.php file on line 592 for callback typos and line 618 for the other rule typos.
#7

[eluser]helmutbjorg[/eluser]
Just for interests sake... Seeing as it is not slowing the validation process and I think we can assume that every rule that people add they actually want a corresponding function to exist. Is this the sort of thing you (codeigniter) could include in a future release? Or are the implications of what could happen to existing code people have written in previous versions deter you from including something like this...

I'm not exactly worried about it I'm just interested in your thoughts.
#8

[eluser]xwero[/eluser]
I don't decide what goes in CI or not, i'm just a serial poster Smile

Before i mentioned a log entry and i guess that is the only thing you can do to make you aware of non existent methods that is backwards compatible. And it's also better if you make more than one typo.
When you get an error page for each typo you could get frustrated with the library. But like you said it's the way you are used to working with php.
#9

[eluser]helmutbjorg[/eluser]
Hahaha... surely after 3646 posts they could put your name on the product.
#10

[eluser]voidstar[/eluser]
Thanks, xwero and helmutdesign, for your replies. Very helpful!

As an aside, the documentation says that the rules may be invoked as discrete functions. If a user misspelled a function name here, it would be a fatal error. Doesn't it seem inconsistent that when the same mistake is made as a rule, it's ignored? (Or maybe I need to reread Emerson's quote on the subject. :-) )

Although it's not an original idea, perhaps CI should have a $config[] value for more, or less, stringent error checking of things like the Form Validation rules.




Theme © iAndrew 2016 - Forum software by © MyBB