Jump to content

ucwords not working


garbagedigger

Recommended Posts

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)
	{

Link to comment
Share on other sites

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']));

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.