Basically the title of the thread says it all. I am looking for any info (providing links is fine as I can't seem to find it via Google) on incorporating automatic capitalization in one field on a form. Basically if the submitter fills in the quick brown fox is in the field The Quick brown fox is in the field THE QUICK BROWN FOX IS IN THE FIELD it should be submitted as The Quick Brown Fox is in the Field Anything to get me started?
That would be for display only though, right? I don't think that will help me as the results of the form are used places (like emails, raw code) where CSS won't help.
I am assuming you are using php? If so this should do what you need. $text = ucwords(strtolower($text));
Your are right, it would be only for display. That's what CSS is about. In your case, what you should do is use some server side programming to transform the text before inserting it in, let's say, a database. Javascript could help, but won't as secure as doing it on the other side (the server).
Thats exactly what I want to do...The user enters it however they like and then its converted before being written to the mySQL database.
If you want to keep certain words all lower case you'll need some more coding. A quick pseudo code suggestion. DontWords = Split("in|of|theis|...) OriginalString = split(tolower(form("field")), " ") for each strWord in OriginalString if strWord exists in DontWords then dont capitalise result = result + " " + strWord else capitalise strWord // see above post result = result + "" + strWord end if next result = trim(result) //shave off any extra spaces Code (markup): Where "dontWords" prefferably is some sort of dictionary object that has the exists function built in (or a custom built function DontWord(word)).
This is basically where I am writing to the database which is where I assume I can do this where entry2 needs to have the rule applied <?php include "conn.php"; $info = mysql_fetch_array(mysql_query("SELECT * FROM field6 WHERE varibleexample='$_COOKIE[variableexample]'")); if (!$info) { $info[id] = 0; } $error=""; if($_POST[entry1]=="" || $_POST[entry2] == "" || $_POST[entry3] == ""){ $contents = "All fields are required, hit your browser back button to correct the problem."; } else { //check if submission already exists $sql ="SELECT * FROM field WHERE entry1 = '$_POST[entry1]'"; $rs = mysql_query($sql,$db) or die(mysql_error()); if(mysql_numrows($rs) > 0){ $contents = "Blah Blah Blah."; } else { //Save the data $entry4=trim($_POST[entry4]); $sq = "INSERT INTO field (entry1, entry2, entry3, entry4, entry5, entry6) VALUES ('$_POST[entry1]', '$_POST[entry2]', '$_POST[entry3]', '$entry4', '0', '$entry6')"; @mysql_query($sq) or die(mysql_error()); $contents = "<blah blah blah>"; } } ?> PHP:
I'm not into PHP yet, otherwise I would code it out for you. Will start coding PHP any day now (my actual "space" site ), hope someone else can solve it for you. Do you want to keep "in" and such all lower?
Yes, I will need to include something similar to what you proposed as there is a short list of words that shouldn't be capitalized. Something tells me I will have to also have to code to change them down also. ie. Make The Brown Fox Ran In The Field to The Brown Fox Ran in the Field Then there is the fact that the first word needs to be capitalized even if its one of the no words. I think this is getting a bit too complicated for me as every time I think about it there are more scenarios
Think this should do what you need. Lets use 'entry1' as the example field for this. <?php //Save the data $entry1 = ucwords(strtolower($_POST[entry1])); $entry4=trim($_POST[entry4]); $sq = "INSERT INTO field (entry1, entry2, entry3, entry4, entry5, entry6) VALUES ('entry1', '$_POST[entry2]', '$_POST[entry3]', '$entry4', '0', '$entry6')"; @mysql_query($sq) or die(mysql_error()); $contents = "<blah blah blah>"; } } ?> PHP: In the above I added the first line of code, and in the the insert command you need to change the value from '$_POST[entry1]' to '$entry1' as I have. Again not sure which is actually your title field, just change accordingly.
Make your list of rules in English, in preferntial order (i.e. once one rule is hit for a word you don't follow any more) : e.g. First character is always a capital The words in, a, an, are, the, is and when are always lower case All words start with uppercase letter Writing the script to do it will be easy but defining the rules is the difficult part like what about abbreviations being uppercase, e.g. AM PM WTF This is one of those scripts that may turn into more hassle than it's actually worth.
Thats true although there are rarely abbreviations and those can be fixed by hand. I will start where BigTicket indicated and try to write the rules from there.
Ah, my previous post does not account for that. As dct mentioned you would need to write the rules for all the words to be excluded.
It would probably only save me around 10-15 minutes a day so I am a little bit hesitant to get stuck in and spend a lot of time on it. Thanks for all the posts as I may still do it later.
That could easily be incorporated in my solution, just that the "if" checks if we're on the first word. if strWord exists in DontWords and not on first word then Code (markup): The fact that my PHP skills suck, suck I would have coded this up for you just because I like string handling functions so much (kind of a fetish actually ).