i added a css code to transform the text of my input form however it only displays this and inserts lower case into the database rather than first letter being capitalized.

i looked at the phpstrtoupper, however how would i use this in my input form to change it to upper case letters for first name and last name?

<td>First Name:</td>
                 <td ><input type="text" class="cap"  name="UserFirstName" id="UserFirstName" value="" size="32" /></td>

which class = my css code. how can i use the phpstrtoupper to use in an input form like above code?

many thanks

8 Years
Discussion Span
Last Post by diafol

That should ensure that your html displays db output as first-letter capitalised, regardless of the db data (lowercase or not).

If you want the db data to be first-letter capitalised:

$ufn = ucwords($_POST['UserFirstName']);


This will only change the first letter - if your form input is in a weird format, e.g. benJaMIN, you'll still store BenJaMIN.
Some people use ucwords(strtolower($var)) - to force everything to lower, then first-letter capitalise. I have an issue with that as certain names may have apostrophes, etc, which may indeed require a capital letter in some languages. Dashes will force a capital letter though:

ucwords(strtolower('aNn-mAriE'))    -->  Ann-Marie

What about leaving the entry to the user? After all, they are the experts when it comes to how they should spell their name correctly. If they get it wrong - tough their fault. If they get it right and then you display it incorrectly - ouch!

Edited by diafol: n/a


thanks ardav i tried adding you css to my stylesheet and tried this:

                <th class="table1">First Name:</th>
                <td class="cap"><?php echo($row_WADAclients['UserFirstName']); ?></td>

but displayed it lowercase from db?

what about a javascript or something? how would i use the php code you gave me in my table results or would the code:

$ufn = ucwords($_POST['UserFirstName']);

be in my insert page at top?

many thanks


should be


Sorry - but perhaps that doesn't make much difference - dunno.

You could do this instead of CSS:

<td><?php echo ucwords(strtolower($row_WADAclients['UserFirstName'])); ?></td>

thanks ardav, noticed i could do this within dreamweaver but it is same code as you gave me last there.

many thanks again


OK - does it work? Or are you still looking for a solution?


yes it worked with code generated from dreamweaver which was the same as you had given me.

many thanks

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.