Skip to main content
July 16, 2006
Question

capitalised first letter

  • July 16, 2006
  • 2 replies
  • 282 views
Hi i have a form which is passed to this insert query below, i need the first letters of firstname and surname to be capitalised if they are not in the form, is this possible?

<cfquery name="Insert datasource="Users">
INSERT INTO TempUsers
(Name, firstName, Surname, EmailAddress, Password)
VALUES
('#form.FirstName#', '#form.Surname#', '#form.EmailAddress#', '#form.password#')
</cfquery>
This topic has been closed for replies.

2 replies

Participant
July 16, 2006
Place this function in say the top of the page then use the function anywhere in the page. You could also create it in the request scope and use it just there or make it permament. Your choice.

<!------------------------------------------------------------------>
<!--- Return string with initial letter capitalized. --->
<!------------------------------------------------------------------>
<cfscript>
function capitalizeFirstLetter(word) {
return UCase(Mid(word,1, 1)) & LCase(mid(word, 2, len(word)));
}
</cfscript>

<cfquery name="Insert datasource="Users">
INSERT INTO TempUsers
(Name, firstName, Surname, EmailAddress, Password)
VALUES
('#capitalizeFirstLetter(form.FirstName#)', '#capitalizeFirstLetter(form.Surname)#', '#form.EmailAddress#', '#form.password#')
</cfquery>
Inspiring
July 16, 2006
NewWord = ucase(left(OldWord, 1)) & right(OldWord, len(OldWord) -1);