I am writing some code to give a live response to the user on the validity of a form using AJAX. I have to check this length and if the field is empty I now want to sanitize the input of users and if sateted input is different than the original input from users, then tell them which characters are not allowed.
The code I have written works except for some characters No answer '£' symbol result I think it is related to json_encode and its encoding
Here is the code:
$ user_input = 'asdfsfs £'; $ Strip_are = str_split (bar ($ 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 bar ($ input) {Return elements (Strip_tags ($ input), ENT_QUOTES);}
Hope anyone can find a solution.
If it is done through AJAX, then you have to type a javascript function to complete it .
A JSON object of the server return format
{origin: 'asdfsfs £', edited: 'asdfsfs', illegal chairs: ['£']}
In your HTML, you must have an empty element next to the form input field, where you have the form verification message
& lt; Input type = "text" id = "myTextField" /> & Lt; Span id = "myTextFieldLabel" />
Now let's update the contents of the myTextFieldLabel component according to your Javascript verification data
Scene
Comments
Post a Comment