admin管理员组

文章数量:1431720

How correct validate data from user to save in database from inputs?

I use this for textfields:

        $name = trim(sanitize_text_field($_POST['name']));

But if i add special signs like "&*({} Something like this ^&({}<>", then they add without a problem.

I need add only "Something like this" without special signs.

How correct validate data from user to save in database from inputs?

I use this for textfields:

        $name = trim(sanitize_text_field($_POST['name']));

But if i add special signs like "&*({} Something like this ^&({}<>", then they add without a problem.

I need add only "Something like this" without special signs.

Share Improve this question asked Apr 22, 2019 at 16:44 JaronJaron 458 bronze badges 1
  • 2 For reference, WordPress provides some guidance for validating and sanitizing user input: codex.wordpress/… – MikeNGarrett Commented Apr 22, 2019 at 16:49
Add a comment  | 

1 Answer 1

Reset to default 3

Try $name = trim( sanitize_user( $_POST['name'], true ) );

Be sure that the function does what you want! Read here

本文标签: pluginscorrect validate inputs