hi,

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

Member Avatar for diafol
.cap{
   text-transform:capitalize
};

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']);

//Caveat

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!

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

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

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

Member Avatar for diafol
.cap{
   text-transform:capitalize
};

should be

.cap{
   text-transform:capitalize;
}

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

Member Avatar for diafol

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

Member Avatar for diafol

Great - mark as solved please.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.