Welcome Guest, Not a member yet? Register   Sign In
Form Validation + optional fields
#1

[eluser]davste[/eluser]
Hi,

I've gotten to discover an "error" or bug, if you don't include "require" in the set_rules() function.

Example shown below:
Code:
$this->form_validation->set_rules ('new_folder', 'Folder name', 'callback__convert_whitespace|alpha_dash');

_convert_whitespace () is a function that replaces whitespaces with -A1234A- (because alpha_dash does not support whitespace). If I remove the callback, everything works.

If I use "require" also, the form wont be submitted if the input value is something like "< script >".

If I use the code above, _everything_ passes although I have "alpha_dash". What to do?

Code:
function _convert_whitespace ($str) {
        return str_replace (' ', '-123ABA-', $str);
    }
It just does not make any sense.

What I want to do:
* Field is optional
* If data, check for a valid name (alpha_dash). Also accept whitespace
#2

[eluser]Thorpe Obazee[/eluser]
I don't think I'm getting it...

Why use alpha dash when you accept whitespace?

You can use regex in the callback if you want to include whitespace.




Theme © iAndrew 2016 - Forum software by © MyBB