Jump to content


Trim function not working

trim required form

  • Please log in to reply
3 replies to this topic

#1 RMaynard

RMaynard

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 23 November 2017 - 04: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.

 

 



#2 RMaynard

RMaynard

    Newbie

  • Members
  • Pip
  • 6 posts

Posted 27 November 2017 - 02: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.



#3 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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. 



#4 RMaynard

RMaynard

    Newbie

  • Members
  • Pip
  • 6 posts

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. 







Also tagged with one or more of these keywords: trim, required, form

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users