does anyone know a bit of php script that formats every <input type=”text”> tag inside a form so that the first letter of each word becomes a capital letter?
@bokehMar 31.2006 — #Just a quick question: Are you trying to capitalize the first letter of the string or the first letter of each word in the string?
#The following array contains the fieldnames of the inputs you want to capitalize $to_capitalize = array('fieldname1', 'fieldname2', 'fieldname3', 'fieldname4');
foreach($to_capitalize as $fieldname) { $_POST[$fieldname] = ucwords($_POST[$fieldname]); }
@bokehMar 31.2006 — #whilst we got the thread running, how would i alter this code to make only the first letter of the string capital?[/QUOTE]ucfirst()
@peteybauthorMar 31.2006 — #thank you....theres a slight problem.
i think theres something wrong with my script. if i explain the symptoms hopefully someone can help.
my script is split into two sections, top and bottom. the top is made up of php validation for the html forms, which are at the bottom.
when the user fills out their details and presses either submit button the form actions ['PHP_SELF'].
my code is structed as follows:
1) form submitted
2) mysql connect
3) $errors = array();
4) validation - eg is_numeric, empty etc
(this is for each field and if any are wrong the $errors[] is designated)
5) if the errors array is empty they either move forward/backward depending on which button pushed
6) if errors array not empty stay on page and show errors
7) mysql close
Now onto the prob. If the user enters data and submits the form with errors in the array the page is reloaded with the errors displayed but the ucwords is not applied, then if the user resubmits the form with errors again the page is reloaded but the ucwords is applied.