How can I enable HTML in a text field so that users can enter HTML in the text field and when submitted, the HTML gets parsed and shown in the browser? Now, I'm using the normal form element for the text field as:
<input id="todo" type="text">
What do I need to change? The type
?
You don't have to do anything. HTML is text, so users can type HTML into a text field if they like.
Changing the type to html
just makes it an unknown type, so browsers treat it as text
.
If you are accepting HTML then you need to carefully sanitise it before displaying it back to the browser, otherwise you are opening up an XSS security vulnerability.
If you would like to enable HTML markup in input field, use <textarea id="todo"></textarea>
It will give you a much bigger box.
Optionally you can use TinyMCE which is easy to use and powerful WYSIWYG tool.
But to show the code when submitted you need to know PHP, Python programming language or something like those.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With