Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable HTML in input text field?

Tags:

html

forms

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?


2 Answers

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.

like image 101
Quentin Avatar answered Sep 16 '25 17:09

Quentin


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.

like image 35
Tusk Avatar answered Sep 16 '25 17:09

Tusk