I am creating a directory where the users are able to post articles. To get the values to be posted I am using inputs html elements and using $.post to save the data in the database.
However, I have a problem that if an user writes some html code in the article it is saved formatting the code.
for example if the value entered is:
<input type="text" value="this is an article title <script>$("body").remove();</script>">
when the post is submitted the page will load also the js script removing the body.
How can avoid this and tell that in the input field there is a script, or formatting the script to show as a text?
htmlspecialchars().$title = htmlspecialchars(filter_input(INPUT_GET, "title"), ENT_QUOTES);