cliffem Posted October 25, 2014 Share Posted October 25, 2014 new account form has the usual; firstname, last name company, street address etc. Talents write in ALL uppercase, lowercase everything but proper case. Don't know where to apply ucwords and strtolower to convert values into proper case. Code as is: <form action="https://www.website.com/?page=step3" method="POST" name=myForm id="commentForm" class="cmxform"> <?php foreach($_POST as $key => $value){ ?> <input name="<?php echo $key ?>" type="hidden" value="<?php echo $value ?>" /> <?php } ?> <hr> <div class="linea"> <div class="itemlabel">Nombre: <br>Name: </div> <div class="cajita"><input type="text" class="required" name="nombre" /></div> </div> Thank you for any solutions/suggestions Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 25, 2014 Share Posted October 25, 2014 Try applying ucwords to $value? Quote Link to comment Share on other sites More sharing options...
cliffem Posted October 25, 2014 Author Share Posted October 25, 2014 Many different ways; none work. Guessing the way is to apply the operation BEFORE $key => $value; but can't figure it out. This doesn't produce results; quite the opposite, page will not display. value="<?php echo ucwords($value); ?>" or after this code: <div class="cajita"><input type="text" class="required" name="nombre" /></div> Can also code so that data retrieval is "cased" the right way, but that is sloppy work. Need the user's input to be cased properly when added to db. Quote Link to comment Share on other sites More sharing options...
blacknight Posted October 25, 2014 Share Posted October 25, 2014 here is a decent function that may help you out http://php.net/manual/en/function.ucwords.php#96179 Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 25, 2014 Share Posted October 25, 2014 You should learn how to create your output in an easier to read (and write) way. foreach($_POST as $k=>$v) { $ucv = ucase($v); echo "<input name=$k type='hidden' value='$v'>"; } See how easy that is to read? And how easy to type? Although the whole exercise seems odd. You're grabbing a set of inputs and then creating html form output? Uhhh - don't you want to USE the post values for something rather than write them back out? Also - you have other errors in your posted code. Turn on error checking to see. (See my signature) Quote Link to comment Share on other sites More sharing options...
Barand Posted October 25, 2014 Share Posted October 25, 2014 Try $data = array ( 'firstname' => 'JOHN', 'lastname' => 'SMIth', 'address' => '2 EFFIN ClOse' ); foreach ($data as $key => &$value) { $value = ucwords(strtolower($value)); } View results echo '<pre>',print_r($data, true),'</pre>'; Array ( [firstname] => John [lastname] => Smith [address] => 2 Effin Close ) Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 25, 2014 Share Posted October 25, 2014 Be careful about putting too much logic to try an interpret correct case for people's names. There are plenty of names that have uppercase letters within the name (as opposed to just the first letter). E.g. "Beverly D'Angelo". And there are valid names that start with a lower case character. Any logic you use is bound to screw up someone's name. Perhaps, you can test each name. if it is all caps or all lower case - then modify it. But, even that won't be perfect. Quote Link to comment Share on other sites More sharing options...
cliffem Posted October 25, 2014 Author Share Posted October 25, 2014 You should learn how to create your output in an easier to read (and write) way. foreach($_POST as $k=>$v) { $ucv = ucase($v); echo "<input name=$k type='hidden' value='$v'>"; } See how easy that is to read? And how easy to type? Although the whole exercise seems odd. You're grabbing a set of inputs and then creating html form output? NO Uhhh - don't you want to USE the post values for something rather than write them back out? NO. Not writing back out; saving them to table. Also - you have other errors in your posted code. Turn on error checking to see. (See my signature) 1- Was coded for me. I am trying to Proper case the data BEFORE it enters the table. 2- There are over 30 inputs to the form. Names, address, phones (taken care of), URLS, etc. Quote Link to comment Share on other sites More sharing options...
cliffem Posted October 25, 2014 Author Share Posted October 25, 2014 here is a decent function that may help you out http://php.net/manual/en/function.ucwords.php#96179 Thank you. Aware of it years ago. Use it elsewhere on site. The problem is WHERE do I apply it in this code: Need to ucwords() the values (i.e. "nombre") before they go into database. If I could - foreach($_POST as $key => ucwords($value)) that would be the simplest solution. Doesn't work. I am sure it is a matter of my ignorance and just a matter of someone that has come across this issue before. <form action="http://www.ainmpr.com/?page=step3" method="POST" name=myForm id="commentForm" class="cmxform"> <?php foreach($_POST as $key => $value){ ?> <input name="<?php echo $key ?>" type="hidden" value="<?php echo $value ?>" /> <?php } ?> <div class="linea"> <div class="itemlabel">Nombre: <br>Name: </div> <div class="cajita"> <input type="text" class="required" name="nombre" /> </div> </div> <div class="linea"> <div class="itemlabel">Segundo Nombre: <br>Middle Name: </div> <div class="cajita"> <input type="text" name="nombre2" /> </div> </div> Quote Link to comment Share on other sites More sharing options...
cliffem Posted October 25, 2014 Author Share Posted October 25, 2014 Be careful about putting too much logic to try an interpret correct case for people's names. There are plenty of names that have uppercase letters within the name (as opposed to just the first letter). E.g. "Beverly D'Angelo". And there are valid names that start with a lower case character. Any logic you use is bound to screw up someone's name. Perhaps, you can test each name. if it is all caps or all lower case - then modify it. But, even that won't be perfect. That, Psycho, is the issue: Where do I modify the value? I have no problem with occasional "D'Angelo". Can be corrected manually or tested as you say. If a character does not belong to an array of acceptable characters, then, apply different rules or flag for inspection. My issue is that I get ALL CAPS, no caps, a mixed case of entries. Then when the data is used to create reports or even their Headshot Resume for movie directors it is GIGO. Quote Link to comment Share on other sites More sharing options...
boompa Posted October 25, 2014 Share Posted October 25, 2014 <?php $data = array ( 'firstname' => 'JOHN', 'lastname' => 'SMIth', 'address' => '2 EFFIN ClOse' ); function properCase($val) { // Convert to lower, then proper-case it. return ucwords(strtolower($val)); } // Apply the above function to each value in the array. $tada = array_map('properCase', $data); // Print the array. foreach($tada as $key => $value) { print "$key => $value\n"; } Results in: firstname => John lastname => Smith address => 2 Effin Close Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.