⚠ 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

Trim function not working



RMaynard

RMaynard
  • profile picture
  • Member

Posted 23 November 2017 - 16:44 PM

When I try to use trim in the following line in my controller it applies the required, but not trim. The string '      some thing' gets stored to the database as '      some thing' not 'some thing' . I need to have spaces in the string so alpha_dash is not going to work for me either. Are additional libraries of helpers need to make trim work?

 

$crud->set_rules('fname','First Name','trim|required');

 

Any help is greatly appreciated.

 

 


RMaynard

RMaynard
  • profile picture
  • Member

Posted 27 November 2017 - 14:07 PM

Anybody? This same question was asked in 2013, and I wonder if this is still a bug in the script.

I finally wrote a callback to do it, but can't believe I am one of two people that need to remove white space from user data.


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 28 November 2017 - 04:21 AM

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. 
 

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. 


RMaynard

RMaynard
  • profile picture
  • Member

Posted 02 December 2017 - 01:08 AM

The trim appears to do nothing. If you leave a required field blank and try to update, it will throw an error saying the field is required which is as it should. Putting blank spaces before and/or after data in a field set to trim neither trims the data nor throws an error, so it appears to have no useful purpose, therefore, I don't even see why it is mentioned in the documentation if it does nothing.