⚠ 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

Uppercase, Lowercase or Capitalized text on input



fdias
  • profile picture
  • Member

Posted 13 July 2012 - 17:32 PM

I'm sharing here what I answered Anto on a support thread.

You can use this code when you wish the input is converted to uppercase, lowercase or capitalized letters.

TO UPPERCASE:

[size=3][font=arial,helvetica,sans-serif]On the crud method you use before render:[/font][/size]

[size=3][font=arial,helvetica,sans-serif]

$crud->callback_add_field('fieldname',array($this,'callback_to_upper'));
[/font][/size]

[size=3][font=arial,helvetica,sans-serif]Callback function:[/font][/size]

[size=3][font=arial,helvetica,sans-serif]

function callback_to_upper()
{
return '<input type="text" name="fieldname" style="text-transform:uppercase;">';
}
[/font][/size]

TO LOWERCASE:

[size=3][font=arial,helvetica,sans-serif]On the crud method you use before render:[/font][/size]

[size=3][font=arial,helvetica,sans-serif]

$crud->callback_add_field('fieldname',array($this,'callback_to_lower'));
[/font][/size]

[size=3][font=arial,helvetica,sans-serif]Callback function:[/font][/size]

[size=3][font=arial,helvetica,sans-serif]

function callback_to_lower()
{
return '<input type="text" name="fieldname" style="text-transform:lowercase;">';
}
[/font][/size]

TO CAPITALIZE:

[size=3][font=arial,helvetica,sans-serif]On the crud method you use before render:[/font][/size]

[size=3][font=arial,helvetica,sans-serif]

$crud->callback_add_field('fieldname',array($this,'callback_to_cap'));
[/font][/size]

[size=3][font=arial,helvetica,sans-serif]Callback function:[/font][/size]

[size=3][font=arial,helvetica,sans-serif]

function callback_to_cap()
{
return '<input type="text" name="fieldname" style="text-transform:capitalize;">';
}
[/font][/size]

Hope you like it!

Cheers.

Robert
  • profile picture
  • Member

Posted 18 June 2013 - 08:39 AM

Thanks for this  .. i used it to.


edramirez
  • profile picture
  • Member

Posted 02 November 2013 - 17:36 PM

Doing it that way would make the data appear to be in uppercase or lowercase or capitalized. But the actual data stored would not be affected. Hence, if the code were included as above to make the data uppercase but the keyboard was in lowercase, the display would be in uppercase but the data stored into the table would be in lowercase. To store the data in uppercase, we would need to add the following:

 

1. before the render:

$crud->callback_before_insert(array($this,'prepare'));
$crud->callback_before_update(array($this,'prepare'));
 

 

2. as a separate function to save as uppercase:

public function prepare($post_array)
{
$post_array['fieldname'] = strtoupper(trim($post_array['fieldname']));
return $post_array;
}
 
 
Ed

lcoulon
  • profile picture
  • Member

Posted 27 January 2019 - 22:45 PM

Hello

 

Is there a way to get several input fields changed to uppercase with a single callback ?

 

This works perfectly to changed ONE field only, but calling the callbacks several time does work at all if we try to get multiple fields (textboxes) ?

 

I need to more than one field modified but do not find the proper way to do it.

 

Could someone post any example showing how to do this please ?

 

Many thanks,