Borderline Posted January 15, 2011 Share Posted January 15, 2011 HiI have an entry form for an online competition, and I'm fighting a losing battle asking people to take care when inputting their information. Very regularly, I get entry names in lowercase and uppercase, and while it isn't a matter of life and death issue, I do find it quite irritating.I've been looking into some solutions, the first of which was CSS. Text transform has worked great in instances where the information is input in lowercase, but hasn't worked for the uppercase entries. I've looked at the PHP options, and would like some advice. ucwords() - is this used in the actual entry form code? My code currently looks like this, would I be able to use ucwords within this code? $stable = mysql_real_escape_string($_POST['stable']); Have noticed this fuction , which covers making the data upper or lower case from the WHERE statement, is it possible to do this with capitalizing the first letter of each word?Any advice would be gratefully received. Link to comment Share on other sites More sharing options...
thescientist Posted January 15, 2011 Share Posted January 15, 2011 http://php.net/manual/en/function.ucwords.php$stable = mysql_real_escape_string(ucwords($_POST['stable'])); Link to comment Share on other sites More sharing options...
boen_robot Posted January 15, 2011 Share Posted January 15, 2011 If your form accepts non latin data... like, if it's all UTF-8 encoded... you might want to use mb_convert_case() instead.Anyhow, you can use either of these functions in your code by simply processing the string before it's turned into a DB safe one, i.e. $stable = mysql_real_escape_string(mb_convert_case($_POST['stable'], MB_CASE_TITLE, 'UTF-8')); And for the record, CSS also has the "capitalization" value of text-transform to do just that upon display, like for example: h2 {text-transform:capitalize;} But keep in mind that transformations done using CSS are only applicable on page view - the actual data in the DB would still be exactly what the user entered.I observed the problem you had in mind... yep... it won't work unless you "manually" lowercase the data first. Link to comment Share on other sites More sharing options...
Borderline Posted January 15, 2011 Author Share Posted January 15, 2011 Brilliant, thank you both so much. Really appreciate the speedy response. Link to comment Share on other sites More sharing options...
chokk Posted January 17, 2011 Share Posted January 17, 2011 How about using the javascript function toLowerCase() before submitting user input to the server? Link to comment Share on other sites More sharing options...
dsonesuk Posted January 17, 2011 Share Posted January 17, 2011 because its better to use server script to process form\database data, than javascript which could be disabled.$stable = mysql_real_escape_string(mb_convert_case(strtolower($_POST['stable']), MB_CASE_TITLE, 'UTF-8'));should convert all to lowercase, then to propercase/ucase Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.