Welcome Guest, Not a member yet? Register   Sign In
1 error message at the time, custom regexp check on field
#1

[eluser]CrustyDOD[/eluser]
Before i write my own 'addon' to the core, i'm just double checking that i haven't missed this somewhere in the guides and code..

1 error message at the time
Right now as far as i know (just started using CI) you have two options:
- Show ALL error messages at once
- Show error message per field (still shows more then just one error message)

I would like to show only one error message at the time by calling just one function. Is there a functions in the CI core right now that does this?

For example look at youtube sign up. If you miss one field, it shows just one error message for field you missed, and not ALL like CI is doing it right now.

custom regexp check on field
Is there a rule for custom regexp on a field?
Let's say i have drop down with values 1 and 2. I want to check that what someone submitted really is a value 1 or 2, and not 0, 3,4,5,... (faking form in this case).

Does this rule exist in the CI core?

Like i said, i'm just double checking cause i'm new to CI and i really like it.. and don't want to write something that already exist Smile
#2

[eluser]xwero[/eluser]
[quote author="CrustyDOD" date="1224600091"]1 error message at the time
Right now as far as i know (just started using CI) you have two options:
- Show ALL error messages at once
- Show error message per field (still shows more then just one error message)

I would like to show only one error message at the time by calling just one function. Is there a functions in the CI core right now that does this?
[/quote]
I can see your point but i think it will make the error message mechanism too complex. What you want is a hierarchy in the rules based on first come first served. You would have to set some sort of flag if the rules are hierarchy based or not and then you have to change the way run works.

[quote author="CrustyDOD" date="1224600091"]custom regexp check on field
Is there a rule for custom regexp on a field?
Let's say i have drop down with values 1 and 2. I want to check that what someone submitted really is a value 1 or 2, and not 0, 3,4,5,... (faking form in this case).[/quote]
There is no general regex rule. All regex rules are in a method.

I don't think someone wrote these things so go ahead Wink
#3

[eluser]CrustyDOD[/eluser]
I was thinking something like:
Code:
class MY_Validation extends CI_Validation
{
    function __construct()
    {
        parent::CI_Validation();
    }

    public function showFirstError()
    {
        // $this->_error_array contains ALL errors created by RUN function
        // You just take item at [0] in array if it exists and show it, job done..
        return $this->_error_array[0];
    }
}
That's all i want, first come first served. Simple Smile

What did you mean by:
Quote:All regex rules are in a method.

Thanks for the reply tho! I shall include this two things then..
#4

[eluser]xwero[/eluser]
valid_email, alpha, alpha_numeric, alpha_dash, ... are all regex rules so if you want to add a new regex rule i suggest you put it in it's own method instead of creating a catch all regex method.

Fetching the first error is fetching the first error of the field you added first to the rules. In the current validation library there is no way to get the first error of a certain field.
In the new library, see SVN, it is possible because there the level 1 keys are the fieldnames.
#5

[eluser]wiredesignz[/eluser]
Code:
list($errmsg) = split("\n", $this->validation->error_string);




Theme © iAndrew 2016 - Forum software by © MyBB