What is the best/safest way to ensure that if a user enters any html or javascript (or even SQL) into a form that it all gets cleaned out and only displays plain text (or will display their html in plain text) or gives the user an error? Obviously I'm trying to prevent XSS and any kind of injection as well as I don't want users to try to and disturb the display of my page with their own HTML. Ideally I would prefer to not have the HTML written to the database.
EDIT: I am not sure who to mark as the answer as you all solved this problem from different angles