Jump to content


[ANSWERED] A problem in validations. Set rules doesn't filter.

validation set_rules

  • Please log in to reply
19 replies to this topic

#1 ali_fattahi

ali_fattahi

    Member

  • Members
  • PipPip
  • 16 posts

Posted 27 February 2012 - 08:50 AM

hello dear friends.
I have a problem in form validation on gerocerycrud
this is my code :
$crud->set_rules('name','Category Name','xss_clean|required|encode_php_tags|prep_for_form|strip_tags|prep_url');

but only "required" working good and other rules such as "encode_php_tags" doesn't work .
how can I solve this problem ?


Best Regards
Ali

#2 noskov

noskov

    grocery CRUD Guru

  • Advanced Member
  • PipPipPip
  • 175 posts
  • LocationKiev

Posted 27 February 2012 - 10:53 AM

hi!
if i'm not mistaken, validation in grocerycrud works like validation in codeigniter.
look in the list of codeigniter rules http://codeigniter.c...l#rulereference

#3 ali_fattahi

ali_fattahi

    Member

  • Members
  • PipPip
  • 16 posts

Posted 27 February 2012 - 03:49 PM

Hello dear
no , as in the http://www.grocerycr...alidation_rules described,, the rules is the same as the codeigniter and we can use both of them .

#4 noskov

noskov

    grocery CRUD Guru

  • Advanced Member
  • PipPipPip
  • 175 posts
  • LocationKiev

Posted 27 February 2012 - 05:34 PM

hm... in that example said, that it's possible to use validation rules of CI, but there is nothing about prepping functions.

#5 ali_fattahi

ali_fattahi

    Member

  • Members
  • PipPip
  • 16 posts

Posted 27 February 2012 - 05:45 PM

thanks for reply .
humm . then how can i use several validation together for each fields ?

Best Regards
Ali

#6 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,101 posts
  • LocationLondon

Posted 27 February 2012 - 07:54 PM

@noskov.biz is right
In your case you can use the callback of codeigniter set_rules. You can see an example at: http://www.grocerycr...p__262#entry262
Posted Image

#7 ali_fattahi

ali_fattahi

    Member

  • Members
  • PipPip
  • 16 posts

Posted 27 February 2012 - 08:40 PM

my problem is not callbacks .
the "xss_clean|required|encode_php_tags|prep_for_form|strip_tags|prep_url" doesn't work
for example : for that rules , encode_php_tags dont work in rules and if i enter a php code it will insert the php code to database .

#8 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,101 posts
  • LocationLondon

Posted 27 February 2012 - 08:44 PM

Those are validation rules not filtering rules.
So the only thing that xss_clean, encode_php_tags, prep_for_form, ...e.t.c. do is just to "validate" your fields. So if the function returns true this means the validation works, if not it will return a message for this. So that it can continue to the next step, but not filter them.

To filter them you have to use grocery CRUD callbacks.
Posted Image

#9 ali_fattahi

ali_fattahi

    Member

  • Members
  • PipPip
  • 16 posts

Posted 27 February 2012 - 10:27 PM

thanks so much :X

#10 Cèsar Martí

Cèsar Martí

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 12 March 2012 - 11:13 AM

My validation is not working either

$crud->set_rules('youtube', 'Youtube', 'trim|prep_url|strtolower|valid_url|xss_clean|max_length[250]');


#11 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,101 posts
  • LocationLondon

Posted 13 March 2012 - 12:06 AM

grocery CRUD just use the validation rules to validate and not to filter. So this is not a bug. It is just the way grocery CRUD works.

If you want to filter the data you can use the callback_before_insert and the callback_before_update.
Posted Image

#12 carlinchisart

carlinchisart

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 18 March 2012 - 10:37 PM

hi, i don't know if in this post this topic is valid.

My problem is when i use $crud->set_rules to valid email
    $crud->set_rules('correo_resp_tec', 'Email', 'valid_email');

the required field function don't work
$crud->required_fields('nombre_responsable_tecnologia','cargo_resp_tec','tiempo_resp_tec','celular_resp_tec','correo_resp_tec');

if I comment the line set_rules the required fields work, the rule work fine when I put data in the field, but if i don;t put any in the field, and save the register is save.

so i don't know what hapenned.

I use grocery CRUD 1.2.

#13 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,101 posts
  • LocationLondon

Posted 19 March 2012 - 07:23 AM

When you add a custom set_rules you have to write again the required fields. So in your case you just need to have :

$crud->set_rules('correo_resp_tec', 'Email', 'valid_email|required');

and it will work fine.
Posted Image

#14 carlinchisart

carlinchisart

    Advanced Member

  • Members
  • PipPipPip
  • 67 posts

Posted 19 March 2012 - 03:29 PM

is perfect, I'm sorry for the question, but i don't know this part.

#15 webpaul

webpaul

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 17 April 2012 - 10:34 AM

grocery CRUD just use the validation rules to validate and not to filter. So this is not a bug. It is just the way grocery CRUD works.
If you want to filter the data you can use the callback_before_insert and the callback_before_update.


It would be great if in the future versions of grocery CRUD we could use the complete set_rules of Codeigniter (filter and validation) because I think It's one of the best things of CI

#16 j-gun

j-gun

    Member

  • Members
  • PipPip
  • 20 posts

Posted 18 September 2012 - 07:06 AM

@web-johnny

how to stop insert action in grocery CRUD when there is duplicate content on the database?

thanks

#17 Trần Đình Trọng

Trần Đình Trọng

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 23 April 2013 - 02:50 AM

When you add a custom set_rules you have to write again the required fields. So in your case you just need to have :
 

$crud->set_rules('correo_resp_tec', 'Email', 'valid_email|required');

and it will work fine.

How to custom error messeger when set rules, ex: I want to replace "The %s field must contain a unique value."  to "Trùng tên đăng nhập".

Thanks



#18 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 23 April 2013 - 10:38 PM

How to custom error messeger when set rules, ex: I want to replace "The %s field must contain a unique value."  to "Trùng tên đăng nhập".

Thanks

 

From page: http://ellislab.com/...l#settingerrors

 

Setting Error Messages

All of the native error messages are located in the following language file: language/english/form_validation_lang.php

To set your own custom message you can either edit that file, or use the following function:

$this->form_validation->set_message('rule', 'Error Message');

Where rule corresponds to the name of a particular rule, and Error Message is the text you would like displayed.

If you include %s in your error string, it will be replaced with the "human" name you used for your field when you set your rules.

In the "callback" example above, the error message was set by passing the name of the function:

$this->form_validation->set_message('username_check')

You can also override any error message found in the language file. For example, to change the message for the "required" rule you will do this:

$this->form_validation->set_message('required', 'Your custom message here');


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#19 Trần Đình Trọng

Trần Đình Trọng

    Newbie

  • Members
  • Pip
  • 8 posts

Posted 24 April 2013 - 02:55 AM

Thanks, davidoster. I have other problem

I have a table with 2 unique feild : username & email.

My code :

$crud->set_rules('username','Tên đăng nhập','is_unique[tblpersonnels.username]');
//Tên đăng nhập is Username(Vietnamese)

 

Add action is ok, but edit action is report unique error, while i am not change username or email in this feild.

 

Thanks



#20 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 25 April 2013 - 01:17 PM

Thanks, davidoster. I have other problem

I have a table with 2 unique feild : username & email.

My code :

$crud->set_rules('username','Tên đăng nhập','is_unique[tblpersonnels.username]');
//Tên đăng nhập is Username(Vietnamese)

 

Add action is ok, but edit action is report unique error, while i am not change username or email in this feild.

 

Thanks

 

 

http://www.grocerycr...ue-doesnt-work/


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr






Also tagged with one or more of these keywords: validation, set_rules

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users