i want to have a textarea where I can edit html code directly. After submitting the form the content if the textarea (with html tags) should be saved to a MySQL database. I use PHP to receive the date and save it to the database. My problem is, that the HTML code is not properly sent to PHP. I do not receive the HTML code but just the text. How could I fix this?
my Form looks like this:
<form method="post" enctype="multipart/form-data" action="form.php">
<textarea name="html_code">
<a href="link">testlink</a>
</textarea>
<input type=submit value="submit"/>
</form>
The form.php should now be abl开发者_如何学Ce to show the content of the textarea
echo $_POST['html_code'];
shows: testlink
I want: <a href="link">testlink</a>
Thank you all for your answers. I found the problem. It was Joomla. Joomla removed HTML tags when I got strings via getVar. I had to use the mask option JREQUEST_ALLOWRAW to solve the issue.
JRequest::getVar('html_code', '', 'post' , 'STRING', JREQUEST_ALLOWRAW);
Are you echoing it into an HTML page? Because the code will be parsed into an actual link.
View the source of your output page.
You're using the wrong encoding type.
Instead of "multipart/form-data", it should be "text/plain".
You don't have to encode the data as Doug says above; but it will be encoded for you when you submit the form, so don't forget to decode before using.
Your form should be:
<form method="post" enctype="multipart/form-data" action="form.php">
<textarea name="html_code">
<a href="link">testlink</a>
</textarea>
<input type=submit value="submit"/>
</form>
(No, it's not messed up. They're called HTML entities)
You can use htmlentities() in PHP to achieve that.
精彩评论