⚠ 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

Transform string to uppercase



fdoperezr

fdoperezr
  • profile picture
  • Member

Posted 04 April 2017 - 13:07 PM

Hi, I'm trying to transform a string to uppercase but I want it before grocery grud check in the db if that string already exists. I'm using callback_before_insert to transform the string to uppercase but it doesn't check anything.

 

For example: The input is "a" but in the db exists a field with value "A" so I want to show a error message because is a duplicated field.

 

Sorry for my english.


xheradon

xheradon
  • profile picture
  • Member

Posted 04 April 2017 - 13:26 PM

Well, you can use callback_add_field instead callback_before_insert returning the input with style="text-transform: uppercase;"

 

Anyways callback_before_insert should work, maybe the error is un your code. 


fdoperezr

fdoperezr
  • profile picture
  • Member

Posted 04 April 2017 - 16:58 PM

xheradon, on 04 Apr 2017 - 09:26, said:



Well, you can use callback_add_field instead callback_before_insert returning the input with style="text-transform: uppercase;"

Anyways callback_before_insert should work, maybe the error is un your code.


Edit: It didn´t work that the text show it as uppercase but the data send as however you typed it.
$crud->unique_fields('service_tag','num_inventario');
...
$crud->callback_before_insert(array($this,'antesDeAgregarEquipo'));
...
public function antesDeAgregarEquipo($post_array) {
	   $post_array['service_tag']= strtoupper($post_array['service_tag']); //Método que convierne la cadena el service tag en mayusculas
	   return $post_array;
	}
Here is my code, as you see I convert service tag into uppercase before insert the data into db


I FIXED IT, now it work with unique_fields function, I just changed the charset of db's fields to latin1. Now grocery crud check if service tag is repeated.

xheradon

xheradon
  • profile picture
  • Member

Posted 05 April 2017 - 06:36 AM

Yeah, you can use unique_field but if you wanna edit some row after in grocery crud, you'll get a duplicate field error because of unique_field constraint.