Sanitize a field before submitting a form?
Posted: 2016-12-05 12:52
Hi all,
I have a form with 2 fields: field 1 is a text field; field 2 is a hidden field.
I need to replicate field 1 on field 2 but applying some sort of cleaning to the field 2.
Example:
inserting "My field is clean àèì" in field 1 I should get ""My-field-is-clean-aei".
I already created a function to clean a string (attechad below) but I cannot find a way to use it along ADDT update/insert record server behaviour.
CLEANSTRING:
Can someone help me?
TIA
TOny
I have a form with 2 fields: field 1 is a text field; field 2 is a hidden field.
I need to replicate field 1 on field 2 but applying some sort of cleaning to the field 2.
Example:
inserting "My field is clean àèì" in field 1 I should get ""My-field-is-clean-aei".
I already created a function to clean a string (attechad below) but I cannot find a way to use it along ADDT update/insert record server behaviour.
CLEANSTRING:
Code: Select all
<?php
function CleanString($string)
{
$strResult = str_ireplace("à", "a", $string);
$strResult = str_ireplace("á", "a", $strResult);
$strResult = str_ireplace("è", "e", $strResult);
$strResult = str_ireplace("é", "e", $strResult);
$strResult = str_ireplace("ì", "i", $strResult);
$strResult = str_ireplace("í", "i", $strResult);
$strResult = str_ireplace("ò", "o", $strResult);
$strResult = str_ireplace("ó", "o", $strResult);
$strResult = str_ireplace("ù", "u", $strResult);
$strResult = str_ireplace("ú", "u", $strResult);
$strResult = str_ireplace("ç", "c", $strResult);
$strResult = str_ireplace("ö", "o", $strResult);
$strResult = str_ireplace("û", "u", $strResult);
$strResult = str_ireplace("ê", "e", $strResult);
$strResult = str_ireplace("ü", "u", $strResult);
$strResult = str_ireplace("ë", "e", $strResult);
$strResult = str_ireplace("ä", "a", $strResult);
$strResult = str_ireplace("'", " ", $strResult);
$strResult = preg_replace('/[^A-Za-z0-9 ]/', "", $strResult);
$strResult = trim($strResult);
$strResult = preg_replace('/[ ]{2,}/', " ", $strResult);
$strResult = str_replace(" ", "-", $strResult);
return $strResult;
}
?>
TIA
TOny