correct validate inputs

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

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