Uutiset:

Join the Facebook Fan Page.

Main Menu
Advertisement:

ucfirst on profile fields

Aloittaja Aaron10, elokuu 06, 2014, 11:48:57 AP

« edellinen - seuraava »

Aaron10

For the location field for example, how would I capitalize every word using ucfirst in profile-modify.php:

'location' => array(
'type' => 'text',
'label' => $txt['location'],
'log_change' => true,
'size' => 50,
'input_attr' => array('maxlength="20"'),
'permission' => 'profile_extra',


text-transform: capitalize; works but not if caps lock or shift is on.

margarett

You can either do that via JS while the user types (which should be tricky, given how profile fields are actually shown and stored) or you can do it silently after submission, in Profile-Modify.php, somewhere in
// Save the profile changes.
function saveProfileFields()
{

On the foreach loop, you check if the current item is "location" and, if so, you apply your magic :P
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

LainaaOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

Suggestion (untested)

'location' => array(
'type' => 'text',
'label' => $txt['location'],
'log_change' => true,
'size' => 50,
'permission' => 'profile_extra',
'input_validate' => create_function('&$value', '
$value = ucwords(strtolower($value));
return true;
'),
),
Holder of controversial views, all of which my own.


Aaron10

You can only have it do it while you type in JS, right? ucwords/first can't? It worked anyway so not that bothered. Thanks.

Arantor

Correct, the solution I provided applies server side only. It wouldn't be impossible to do client side too, but there's always the fact that whatever happens on the client side can be trivially ignored by users, i.e. assume whatever happens on the client is still messed up by the time it gets to the server anyway.
Holder of controversial views, all of which my own.


Advertisement: