Sprintf syntax for Field Element

Status
Not open for further replies.

stevelis

Member
How do I type in the sprintf ucwords coding? - (first letter uppercase, rest lowercase)
Would appreciate an example of the coding for the 'Format String' option in the Formatting tab of an element named "fname" using a Field plugin.

Thanks
Steve
Australia
 
Hi

I don't know how can be done vi the 'Format String' option but I suggest to use a php validation like this:

Code:
return ucwords($data);
The above will return all words of the string with capital first letter

There is also another string function which returns a string with capital first letter only in the first word
Code:
return ucfirst($data);

Just don't forget to put the option to 'Replace'
 
Hi dimoss
Thanks and working as wanted
Easy, when you look it the right place and there is help pointing you there - again thanks

Thanks
Steve
Australia
 
Using the ucfirst coding works if the data is entered in lowercase.
If all the data is entered in uppercase, the whole field stills shows uppercase.
Can and how do you combine both ucfirst and strtolower functions into one code for the PHP Code box for Validation?
I can achieve the desired result by having 2 separate Validations, or is this how you do it.


Thanks
Steve
Australia
 
Hi

If your string is more than one word with capital letters you better use this:

Code:
return ucwords(strtolower($data));

This will convert your words with first letter capital but all the rest with lowercase.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top