⚠ 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 rule doesn't work



Jefer
  • profile picture
  • Member

Posted 25 October 2013 - 17:40 PM

I am using trim function in a controller so login field can't contain whitespaces at the end but It doesn't work. The login is saved with white spaces.

 

here is the code.

        $crud = new grocery_CRUD();
 
	$crud->set_table('users');
	$crud->set_subject('Usuario');
	$crud->columns('login','password','admin');
	$crud->fields('login','password','admin');
	$crud->display_as('login','Usuario');
	
	$crud->set_rules('login','Usuario','trim|required');
	$crud->set_rules('password','Clave','required');

what is wrong? or do I have to use a callback?


edramirez
  • profile picture
  • Member

Posted 10 November 2013 - 14:14 PM

From my experience, grocerycrud's set_rules function doesn't operate exactly in the same way as codeigniter's counterpart. That being said, we have to accomplish our desired end in a different way. So, here's how I would do it.

 

Let's say that the login field is of type varchar(10). Make sure that the field is not of type char(10).

 

I would do it this way:

$gcrud->set_rules('login','Usuario','required|alpha_dash|max_length[10]');

 

If the user forces to put any space, the validation rule kicks in.

 

Hope this helps.

 

Ed Ramirez

 

P.S. Don't forget to hit the like button!


RMaynard
  • profile picture
  • Member

Posted 23 November 2017 - 16:30 PM

I can't believe this is still an issue. The alpha_dash won't work for me, as I need to have spaces within the string, but not at the ends.