1

In WordPress, when I try to insert some special characters into an input field and submit, it will automatically remove them. For example, if I insert <hi into a text box, WordPress will remove this word since there is a < character next to it. For example:

enter image description here

As you can see, in this case, WordPress has removed the word <string>. Following are the HTML and PHP codes I am using on my WordPress page.

<!--HTML code for the form-->
<form action="" method="post" target="_blank">
  <input type="text" name="user_input">
  <input type="submit" value="Submit">
</form> 

<?php 
  echo "Output: ".stripslashes_deep($_POST['user_input']);
?>

The same thing happens even if I get similar data from a database(with speicial charactors like <string>) and try to print it into a WordPress page. Is there a way to keep these special characters?

NewGuy
  • 73
  • 1
  • 7
  • Does this answer your question? [Prevent WordPress' default input sanitization](https://stackoverflow.com/questions/68104290/prevent-wordpress-default-input-sanitization) – disinfor Jun 28 '21 at 20:52
  • This exact question was asked a few days ago. – disinfor Jun 28 '21 at 20:53
  • @disinfor Thank you for the comment. No, that answer does not help me at all. I am using the `stripslashes_deep` to take care of the problem that question was having. – NewGuy Jun 28 '21 at 20:55
  • It doesn't matter what you're using. The bountied answer is what works. There is an answer using `stripslashes_deep` but it doesn't work - or doesn't work as expected. – disinfor Jun 28 '21 at 20:56
  • You can also check out the answers here: https://stackoverflow.com/questions/8949768/with-magic-quotes-disabled-why-does-php-wordpress-continue-to-auto-escape-my – disinfor Jun 28 '21 at 20:58
  • @disinfor Those answers do work for striping off backwards slashes. However, when I have a `<` character and a word next to it, it doesn't put a ` \\` in front of it and it just remove the whole word from been displayed. If I have a word like `5 – NewGuy Jun 28 '21 at 22:04
  • 1
    _“If I have a word like `5 – CBroe Jun 29 '21 at 07:57
  • 1
    @CBroe I didn't know about that and what you gave me is the answer. Thank you for this. – NewGuy Jun 29 '21 at 13:49

0 Answers0