Issue with stripping special characters

I have 3 elements in a form. $element1 and $element2 are text fields where the user enters information. $element3 is a calc field that is visible in the form, but it cannot be edited. I have the following PHP in the Calculation box to generate the value for $element4. I have Only Calc on Save set to "Yes". I have Ajax Calculation set to "Yes". All 3 elements are saved to the database.

I need all non letter or number characters stripped from $element1 and $element2 values. And, the values need to be converted to all lowercase. That is what the PHP code is doing.

I'm experiencing issues when there are specific special characters in $element1 and 2. With Ajax calculation on I can see the value of $element3 change in the form as I make changes to the other elements. And it behaves as I would expect. For example:

$element1 = "dog"
$element2 = "cat's"

$element3 will show "dog.cat" - removing the apostrophe.

But, after I save the record and view it again, $element3 value shows "dog.cat039s". It feels like somewhere in the process of actually saving to the database it's replacing the character with it's ASCII value. This only happens with certain characters though. I tested by literally going through and changing the apostrophe to each special character on my key board. The issue happens with these characters: $, ', ", &, <, > All other special characters are stripped when the value is actually saved to the database.

Any insights on this? What am I missing?

Thanks!

$element3 code
--------------------------------------------

$element1 = "{mytable___element1}";
$element2 = "{mytable___element2}";

// Remove characters that are not Alphanumeric.
// Also, convert string to all lowercase.
if(!empty($element1)):
$element1 = strtolower(preg_replace('/[\W]/', '', $element1));
endif;
if(!empty($element2)):
$element2 = strtolower(preg_replace('/[\W]/', '', $element2));
endif;

// Put the pieces of data together
$element3 = $element1 . "." . $element2;

return $element3;
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top