Capitalize first letter of a field

Archived from the Xataface Users forum.

deswong — Thu Jan 15, 2009 3:50 pm

Hi,

Is there any easy way to do this? I have a very simple database to start with, where I have two columns: ID, Colour.

I want to be able to ensure that on entry of Colour (ID is auto-incrementing) that the first letter is capitalized, just for consistency.

Regards,

Des.


deswong — Thu Jan 15, 2009 4:30 pm

I’ve found code as follows:



but how do I inegrate this with Xataface? Or is this redundant as there is something already in place?


shannah — Thu Jan 15, 2009 5:37 pm

If all you want to do is make sure that colour is capitalized, you can do this easily in the beforeInsert() trigger in the delegate class.

e.g.

Code: Select all
function beforeInsert(&$record){     if ( trim($record->val('Colour')) ){         $record->setValue('Colour', ucfirst($record->val('Colour')));     } }

deswong — Thu Jan 15, 2009 7:53 pm

Therefore if I wanted to cap the first letter and make the rest lowercase I would use:

$record->setValue(‘Type’, ucfirst($record->val((strtolower(‘Type’))));

I haven’t done PHP before so I am still trying to wrap my head around this. I love how easy it is to write a web database application with Xataface! I have done more in 1 1/2 days of “tinkering” than I have back in the days of using Java and writing all that code!


deswong — Thu Jan 15, 2009 8:21 pm

Nevermind - took a while to work out - but for those who are interested I achieved this by doing:

Code: Select all
$record->setValue('Type', ucfirst(strtolower($record->val('Type'))));