Welcome Guest, Not a member yet? Register   Sign In
Validation library reloaded aka Validate
#21

[eluser]xwero[/eluser]
In another thread i've did a quick and dirty includes test and the results made me wonder if putting the rules in separate files was such a good idea.

Would you use the rules in your own libraries? This is was the idea which made me split up the rules but if there is no demand for this i can make the library faster by joining the rules in one file like the CI helper files.

I'm going to try to bundle the multi-rules field validation to create a speed increase. I got the idea of a smarty related thread on the forum.
#22

[eluser]codex[/eluser]
[quote author="xwero" date="1208950734"]In another thread i've did a quick and dirty includes test and the results made me wonder if putting the rules in separate files was such a good idea.

Would you use the rules in your own libraries? This is was the idea which made me split up the rules but if there is no demand for this i can make the library faster by joining the rules in one file like the CI helper files.

I'm going to try to bundle the multi-rules field validation to create a speed increase. I got the idea of a smarty related thread on the forum.[/quote]

I think it's best to put them in one file. I personally don't think I will be using the rules seperate anytime soon.
#23

[eluser]codex[/eluser]
I have some questions regarding implementation.

CI validation
Code:
rules:
$rules['username'] = "required|alpha_dash|max_length[30]";

<input type="text" name="username" value="<?=$this->validation->username;?>" size="50" /><?=$this->validation->username_error;?>

Validate
Code:
$validate[0]['input'] = 'username';
$validate[0]['input_type'] = 'post';
$validate[0]['rules'] = 'required|string[words]|maximum[30])'; //?

<input type="text" name="username" value="<?=$this->validate->username;?>" size="50" /><?=$this->validate->error('username', 'post')?>

- linking rules with the pipe char doesn't seem to work
- how do you set the value affter validation (like CI's $this->validation->username)?

Also, $this->validate->error_array has as output:
Code:
Array
(
    [post_user_name] => Gebruikersnaam is verplicht
    [post_user_namf] => is geen email
    [post_user_namg] => User_name is not valid ip address.
)

Is this correct? (name, namf, namg)
#24

[eluser]xwero[/eluser]
Codex sorry for the delay but i wanted to get to the bottom of your problems and put the rules in one file at the same time.

First of all, the validate class isn't working like the CI validation class in many ways so you have to change the way you think.

Linking rules with the pipe char did work but the problem was you used the closing square bracket. In the validate class settings you only have to identify the begin of the parameters of a rule. And additionally you added a rounded bracket to the end of the rules string.
Code:
$validate[0]['rules'] = 'required|string[words]|maximum[30])';
// has to be (by default)
$validate[0]['rules'] = 'required|string:words|maximum:30';

A $this->validation->fieldname value doesn't get generated in the validate class because i think this is a task for the input class. The reason why i haven't uploaded a new version yet is because i want to add an extended input class to the zip for displaying posted and default values.

The output of the error_array was a mistake on my part. Now the output looks like this
Code:
Array
(
    [post_user_name] =>
          Array
          (
              [0] => Gebruikersnaam is verplicht
              [1] => Gebruikersnaam is geen woord
              [2] => Gebruikersnaam is meer dan het maximum
          )
)
The error_array snippet displayed another mistake i made namely displaying rules that require content to be valid. This is changed too.

You can expect a new version tonight or at last tomorrow evening. Thanks for testing.
#25

[eluser]codex[/eluser]
[quote author="xwero" date="1210011926"]
Linking rules with the pipe char did work but the problem was you used the closing square bracket. In the validate class settings you only have to identify the begin of the parameters of a rule. And additionally you added a rounded bracket to the end of the rules string.[/quote]

Yes, I see it. My bad.

Quote:A $this->validation->fieldname value doesn't get generated in the validate class because i think this is a task for the input class. The reason why i haven't uploaded a new version yet is because i want to add an extended input class to the zip for displaying posted and default values.

You can expect a new version tonight or at last tomorrow evening. Thanks for testing.

Thanks. I'm looking forward to the update!
#26

[eluser]xwero[/eluser]
I think the library can almost go into beta. I've added version 0.7 to the wiki which includes following changes. Put validation rules in helper file for faster validation, added input handling code and documentation to the zip, removed load_rules method, added parameter to error method because of changes in the error_array.

Now i have to find the time to add the file validation rules and then the library goes into beta stage.
#27

[eluser]xwero[/eluser]
I've made an error in the MY_Input class. I forgot the semicolon in the alter_x methods. I'm going to release a new version soon but i want to add a some methods at the same time. A group of methods to build the rules array : set_general_input_type, set_rule, set_custom_error. And another method i'm not sure how to name it. In the array it is this
Code:
$this->validate->rules[0]['when']['input'] = 'input_that_needs_to_be_true';
$this->validate->rules[0]['when']['valid'] = TRUE;
// or
$this->validate->rules[0]['when'][0]['input'] = 'input_that_needs_to_be_true';
$this->validate->rules[0]['when'][0]['valid'] = TRUE;
$this->validate->rules[0]['when'][1]['input'] = 'input_that_needs_to_be_true';
$this->validate->rules[0]['when'][1]['value'] = 'some value';
Currently i'm going with set_validate_when, but maybe a native English speaker could come up with a better name.
These rules will only take string parameters because i don't want them to copy an array to the validate rules variable, i've made rules public for that purpose.

And in addition to the error method there will and errors method that will display all the errors from one or more globals.
#28

[eluser]ryeguy[/eluser]
Am I missing something here? Why do I get this:

ERROR

Unable to load the requested file: helpers/validate_helper.php

I don't see that file anywhere in the zip download.
#29

[eluser]xwero[/eluser]
The library has been abandoned, i don't have the files anymore myself. I'm sorry for the inconvenience.

The main thing what is wrong with the library is the overuse of configuration settings.
#30

[eluser]ryeguy[/eluser]
[quote author="xwero" date="1228270172"]The library has been abandoned, i don't have the files anymore myself. I'm sorry for the inconvenience.

The main thing what is wrong with the library is the overuse of configuration settings.[/quote]
Yeah the config settings did seem a bit..intense.

The main reason I wanted this was so I could use validation on just strings. I know you can do it with native CI, but you have to do it like:
$this->form_validator->required($string); and do that for each. Do you know of any libraries that implement string validation like yours did?




Theme © iAndrew 2016 - Forum software by © MyBB