Welcome Guest, Not a member yet? Register   Sign In
Adding to the Form Validation Class
#1

[eluser]frietkot[/eluser]
Hi,

I like the form_validation class very much but it lacks one thing imo.
The ability to check if a form does not matches a given string.

So I added a function to the class.
Code:
function not_matches($str, $field)
{
   return ($str === $field) ? FALSE : TRUE;
}

it's very simular to the matches parameter but a little bit different.
Simple but effective in my eyes.
#2

[eluser]Trae R.[/eluser]
Any chance this could be added to the next CI core release?
#3

[eluser]jpi[/eluser]
This won't work... A line is missing : $field = $_POST[$field];
#4

[eluser]Trae R.[/eluser]
[quote author="jpi" date="1250629347"]This won't work... A line is missing : $field = $_POST[$field];[/quote]

It's working great for me.
#5

[eluser]devbro[/eluser]
He wants comparison to a specific string, not another item from the form
#6

[eluser]jpi[/eluser]
Ahhh ok. I was mistaken by the name of his variables

Quote:Any chance this could be added to the next CI core release?
Ironically I would say that it's not one of the most needed feature...
#7

[eluser]MaD HamsteR[/eluser]
I think the best way in the future is to add PCRE regex check for input fields into validation library)

Something like: required|!match[^cakephp$]|htmlspecialchars

Where ! stands for "doesn't match" and regular expression in brackets.

That would be cool)
#8

[eluser]devbro[/eluser]
because of the syntax of set_rules() it is no possible to use regex strings.

Here is what I thought to go around it:
1. extends form_validation
2. add a function like:
Code:
$this->form_validation->add_regex_string('name','regex_string');

This function will store the given regex_string inside an internal array.

and add this rule as well
Code:
function test_regext($str,$regex_name)
This rule will look at inside array to find a matching regex_name. if so it will test it using preg_match()
and returns the result




Theme © iAndrew 2016 - Forum software by © MyBB