⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

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



ali_fattahi

ali_fattahi
  • profile picture
  • Member

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

noskov.biz

noskov.biz
  • profile picture
  • Member

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.com/user_guide/libraries/form_validation.html#rulereference

ali_fattahi

ali_fattahi
  • profile picture
  • Member

Posted 27 February 2012 - 15:49 PM

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

noskov.biz

noskov.biz
  • profile picture
  • Member

Posted 27 February 2012 - 17:34 PM

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

ali_fattahi

ali_fattahi
  • profile picture
  • Member

Posted 27 February 2012 - 17:45 PM

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

Best Regards
Ali

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 27 February 2012 - 19:54 PM

@noskov.biz is right
In your case you can use the callback of codeigniter set_rules. You can see an example at: /topic/71-different-form-validation-rules-for-insert-and-update/page__p__262#entry262

ali_fattahi

ali_fattahi
  • profile picture
  • Member

Posted 27 February 2012 - 20: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 .

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 27 February 2012 - 20:44 PM

Those are [b]validation [/b]rules [b]not filtering [/b]rules.
So the only thing that [color=#282828][font=helvetica, arial, sans-serif]xss_clean, [/font][/color][color=#282828][font=helvetica, arial, sans-serif]encode_php_tags, [/font][/color][color=#282828][font=helvetica, arial, sans-serif]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. [/font][/color]

[color=#282828][font=helvetica, arial, sans-serif]To filter them you have to use grocery CRUD callbacks.[/font][/color]

ali_fattahi

ali_fattahi
  • profile picture
  • Member

Posted 27 February 2012 - 22:27 PM

thanks so much :X

cesaret_2000

cesaret_2000
  • profile picture
  • Member

Posted 12 March 2012 - 11:13 AM

My validation is not working either

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

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

Posted 13 March 2012 - 00: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.

carlinchisart

carlinchisart
  • profile picture
  • Member

Posted 18 March 2012 - 22: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.

web-johnny

web-johnny
  • profile picture
  • Administrator
  • 1,166 posts

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.

carlinchisart

carlinchisart
  • profile picture
  • Member

Posted 19 March 2012 - 15:29 PM

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

webpaul

webpaul
  • profile picture
  • Member

Posted 17 April 2012 - 10:34 AM

[quote name='web-johnny' timestamp='1331597176' post='769']
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.
[/quote]

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

j-gun

j-gun
  • profile picture
  • Member

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

Trần Đình Trọng

Trần Đình Trọng
  • profile picture
  • Member

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


davidoster

davidoster
  • profile picture
  • Member

Posted 23 April 2013 - 22: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/codeigniter/user-guide/libraries/form_validation.html#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');


Trần Đình Trọng

Trần Đình Trọng
  • profile picture
  • Member

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


davidoster

davidoster
  • profile picture
  • Member

Posted 25 April 2013 - 13: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

 

 

/topic/71-solved-set-rules-is-unique-doesnt-work/