garbagedigger Posted January 19, 2011 Share Posted January 19, 2011 I have a registration page I am creating which passes Ajax data from a form to the function ProcessSignUpData. I am trying to use ucwords on this function for the name, address and city form fields and it isn't working. Any Suggestions what be greatly appreciated! If I am not providing enough information, please let me know! Here is what the code looks like: if ($_POST['ProcessSignUpData']) { usleep(3500000); unset($Data); $Data['OldCardNbr'] = substr(preg_replace("/[^0-9]*/", "", $_POST['SavingsClub']), -; $Data['FName'] = ucwords($_POST['FirstName']); $Data['LName'] = ucwords($_POST['LastName']); $Data['Address1'] = ucwords($_POST['Address1']); $Data['Address2'] = ucwords($_POST['Address2']); $Data['City'] = ucwords($_POST['City']); $Data['State'] = $_POST['State']; $Data['Zip'] = preg_replace("/[^0-9]*/", "", $_POST['ZipCode']); if (ValidateEMail($_POST['EMail'])) $Data['EmailAddr'] = $_POST['EMail']; $Data['HPhone'] = phone_format($_POST['HomePhone']); $Data['WPhone'] = phone_format($_POST['MobilePhone']); $Data['BirthYear'] = preg_replace("/[^0-9]*/", "", $_POST['BirthYear']); $Data['BirthMo'] = preg_replace("/[^0-9]*/", "", $_POST['BirthMonth']); $Data['Sex'] = preg_replace("/[^MF]*/", "", $_POST['Gender']); $NumberOfCards = preg_replace("/[^0-9]*/", "", $_POST['NumberOfCards']); if ($Data['FName'] && $Data['LName'] && $Data['Address1'] && $Data['City'] && $Data['Zip']) { // Check to see if the person is already signed up with a new card number (dupliate signup check) $IsDup = FALSE; // First check database SCVL1 $My->query("select `MembNbr`, `HPhone`, `EmailAddr`, `OldCardNbr` from `member` where `FName` = '" . $My->escape($Data['FName']) . "' and `LName` = '" . $My->escape($Data['LName']) . "' and `State` = '" . $My->escape($Data['State']) . "' and substr(`Zip`, 1, 5) = '" . $My->escape(substr($Data['Zip'], 0, 5)) . "'"); if ($DupCheck = $My->fetchArray()) { do { if (substr($DupCheck['MembNbr'], 0, 1) == "6") { $IsDup = TRUE; if ($Data['EmailAddr'] && $DupCheck['EmailAddr']) { if ($Data['EmailAddr'] != $DupCheck['EmailAddr']) { $IsDup = FALSE; } } if ($Data['HPhone'] && $DupCheck['HPhone']) { if ($Data['HPhone'] != $DupCheck['HPhone']) { $IsDup = FALSE; } } } if ($IsDup === TRUE) break; } while ($DupCheck = $My->fetchArray()); } // Then check database SCVL3 if no dup found in SCVL1 if ($IsDup === FALSE) { $My3->query("select `MembNbr`, `HPhone`, `EmailAddr`, `OldCardNbr` from `tblmember` where `FName` = '" . $My->escape($Data['FName']) . "' and `LName` = '" . $My->escape($Data['LName']) . "' and `State` = '" . $My->escape($Data['State']) . "' and substr(`Zip`, 1, 5) = '" . $My->escape(substr($Data['Zip'], 0, 5)) . "'"); if ($DupCheck = $My3->fetchArray()) { do { if (substr($DupCheck['MembNbr'], 0, 1) == "6") { $IsDup = TRUE; if ($Data['EmailAddr'] && $DupCheck['EmailAddr']) { if ($Data['EmailAddr'] != $DupCheck['EmailAddr']) { $IsDup = FALSE; } } if ($Data['HPhone'] && $DupCheck['HPhone']) { if ($Data['HPhone'] != $DupCheck['HPhone']) { $IsDup = FALSE; } } } if ($IsDup === TRUE) break; } while ($DupCheck = $My3->fetchArray()); } } // Show an error if a dup was found if ($IsDup === TRUE) { Quote Link to comment https://forums.phpfreaks.com/topic/224984-ucwords-not-working/ Share on other sites More sharing options...
webbhelp Posted January 19, 2011 Share Posted January 19, 2011 Have you tried to echo it out directly on the page and see if you get any capitalized letters on the page? Try that and tell Just want to say: CSS got a function which captialize every first letter, just if that is an option... Quote Link to comment https://forums.phpfreaks.com/topic/224984-ucwords-not-working/#findComment-1162055 Share on other sites More sharing options...
garbagedigger Posted January 19, 2011 Author Share Posted January 19, 2011 That is a pretty neat trick with text-transform in CSS but unfortunately it doesn't prevent from making any characters after the first character upper case. So someone could still write: DsdfDFS with the characters after the first character in uppercase. I only want the first character to be upper case and the following characters to remain lowercase. BUT...I did find a fix on my own for this problem. For some reason it works it when I add 'strtolower' which I realized I needed anyway to make the remaining characters lowercase. Crazy! Here is the new example: $Data['FName'] = ucwords(strtolower($_POST['FirstName'])); $Data['LName'] = ucwords(strtolower($_POST['LastName'])); $Data['Address1'] = ucwords(strtolower($_POST['Address1'])); $Data['Address2'] = ucwords(strtolower($_POST['Address2'])); Quote Link to comment https://forums.phpfreaks.com/topic/224984-ucwords-not-working/#findComment-1162111 Share on other sites More sharing options...
DBookatay Posted January 20, 2011 Share Posted January 20, 2011 What would you do if the persons name was OBrien or McCarthy? Quote Link to comment https://forums.phpfreaks.com/topic/224984-ucwords-not-working/#findComment-1162752 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.