Welcome Guest, Not a member yet? Register   Sign In
validation required rule doesn't catch nbsp
#1

[eluser]edwardmolasses[/eluser]
hiya,

I just was wondering how people dealt with this. It's possible to enter  in an input but the required rule in the validation library allows it, so then it will display like there is nothing in that field when i print it on another page. Is there another rule that i could use that would disallow stuff like this?

thanks!
andrew.
#2

[eluser]TheFuzzy0ne[/eluser]
I don't understand what you mean. Can you give an example?
#3

[eluser]edwardmolasses[/eluser]
[quote author="TheFuzzy0ne" date="1209429703"]I don't understand what you mean. Can you give an example?[/quote]

Sure, well it's just a text input form, and i want to make sure it's not empty, and also that it doesn't show up as empty when i display what the user entered in that field on another page. So if i use required as a validation rule it will make sure the user entered text but if they enter html space entities (like & nbsp (have to put a space before & or it will parse it as a space on this page)), they will not be counted. At the moment, the required rule counts the space entity as text and let's it through and then i end up with an empty field when i display it.

I was wondering, should i just write my own callback, or is there a validation rule (ci or user written) for this that might also convert all the other html entities when checking?
#4

[eluser]TheFuzzy0ne[/eluser]
I think that writing your own callback is a great idea. After all, that's why we are able to do so. The validation class cannot validate absolutely everything as it is designed with the basic things in mind, although having the "required" validation rule updated would probably be a good thing to suggest as a feature, or perhaps even report as a bug because a space isn't really valid input for anything useful.
#5

[eluser]Michael Ekoka[/eluser]
include the trim function in your validation rule.

Code:
$rules['username'] = "trim|required";

you should as well escape the html in the output.

Code:
<input type="text" name="username" value="<?= htmlentities($validation->username)?>" />
#6

[eluser]edwardmolasses[/eluser]
Thanks everyone! I think i might have to go with the callback based on what i need.




Theme © iAndrew 2016 - Forum software by © MyBB