Reputation: 3919
I need to send a form to PHP, but one of the fields contains HTML.
When it's in the form it's fine, and will show:
<input id="addNote" value="<div class="line">This is my line</div>"/>
However, when I POST it to the server, the HTML tags have been stripped out, so it comes through as 'This is my line'. What do I need to do to make sure the tags don't get stripped out?
Thanks!
Upvotes: 0
Views: 98
Reputation: 2412
in your .php file use this -
echo htmlentities($_POST['addNote']);
and in your html file use single quote.
<input id="addNote" name="addNote" value="<div class='line'>This is my line</div>"/>
Upvotes: 0
Reputation: 14477
<input id="addNote" value="<div class="line">This is my line</div>"/>
does not work at all!
Since you're using "
to limit the value of the input field, you have two choices:
Change the "
character to '
:
This is my line'/>
Substitute the quotes ("
) inside the value for "
:
This is my line"/>
However, none of this matters if your PHP script deletes HTML tags...
Upvotes: 0
Reputation: 360882
When embedding html-in-html, you should encode the HTML metacharacters so they can't be mis-interpreted:
<input id="addNote" value="<div class="line">This is my line</div>" />
This is especially true with "
characters, as they'll break the form for the parser. e.g.
<input ... value="<div class="line" .... />
^---
The indicated quote will be translated as ENDING the value=
portion, and line"
being the start of some other non-standard/unknown tag attribute.
Upvotes: 3