Reporting sanitized user input to the user via AJAX
Posted
by JimBo
on Stack Overflow
See other posts from Stack Overflow
or by JimBo
Published on 2010-05-17T14:04:17Z
Indexed on
2010/05/17
14:20 UTC
Read the original article
Hit count: 186
I am writing some code to give live feedback to the user on the validation of a form using AJAX. I have got it checking length and if the field is empty. Now I want it to sanitize the users input and if the sanatized input differs from the users original input then tell them which characters are not allowed.
The code I have written so far works except some characters most notably a '£' symbol result in no response. I think it relates to json_encode and its encoding.
Here is the code:
$user_input = 'asdfsfs£';
$strip_array = str_split(strip($user_input));
$orig_array = str_split($user_input);
$diff_array = array_diff($orig_array,$strip_array);
$diff_str = implode(', ',$diff_array);
$final = json_encode($diff_str);
function strip($input){return htmlentities(strip_tags($input),ENT_QUOTES);}
Hope someone can figure out a solution.
© Stack Overflow or respective owner