Form field formatting e.g. to UPPERCASE

Is there a "Yii way" to force an input field to display and save as UPPERCASE?

I’d love to know, before I impliment a “standard” solution becsaue i want to keep it all Yii…

Thanks in advance.

I’m a newbie and as a newbie, this is my answer :D

The closest Yii way is to add the needed CSS ("[font="Courier New"]text-transform:uppercase[/font]") to your form, like this


echo $form->textField($model, 'attribute', array('style' => 'text-transform: uppercase'));

EDIT: well I’m not sure it’ll save it uppercase. Just try and tell us please.

If not, you could add a little snippet in your beforeSave method… using simple PHP: strtoupper() or mb_strtoupper() if UTF-8.

[color="#006400"]/* Moved from Tips, Snippets … to Yii 1.1 General Discussion */[/color]

No that wount save in UPPERCASE, only show, which is still helpful thank you, I will experiement with php… im surprised thats there’s not a ‘Yii way’

The Yii way would be to use what’s built into the core PHP language.

Unless you think Yii should have wrapper around that function? :)

Just thought there might be a clever parameter you could add which formats and saves as uppercase…

I found another approach, first using ‘text-transform: uppercase’ for the style and the use mysql trigger in insert and update database so it’s seem working