How To Capitalize Entries In the Taxonomy Box?

Users can enter term entries in a a taxonomy box (hierarchical) and I want to force that the entries be capitalized (first letter each word).

I tried adding text-transform:uppercase css to the entry box and although it capitalizes the words “during-typing”, it still doesn’t register it as capitalized when the term is added to the entry.

Meaning if the user doesn’t press Shift to capitalize the words, it will show capitalized on the entry box (because of the css), but it will not show capitalized inside the taxonomy box.

Reasons why this is needed:

1) In the front-end when displaying artists names, example like Michael jAckson, or bruce Springsteen, it wouldn’t look good in the front end.

2) Another reason is in the taxonomy box, it doesn’t look good when the artists’ names are not capitalized.

So any answers to the main issue?

Edit: I think an alternative I thought of is to put like a form validation, so when the user clicks “Add New” a popup box will appear saying that he must capitalize the words correctly. The problem is, I’m not very good at javascript, so I don’t know what the code is.

Can anyone provide the code to validate the entry in the taxonomy box if its capitalized correctly when the user clicks the ‘Add New’ button?

2 Answers
2

PHP has a function that does EXACTLY what you’re looking for, ucwords(). Leave the CSS capitalize on there, so that the users know it will be auto-capitalized, and then when you’re filtering the input (which you should be doing ANYWAYS, since it’s user input, run it through ucwords() right before database insertion.

Leave a Comment