Reputation: 5935
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 able to show the content of the textarea
echo $_POST['html_code'];
shows: testlink
I want: <a href="link">testlink</a>
Upvotes: 4
Views: 24868
Reputation: 5935
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);
Upvotes: 4
Reputation: 89626
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.
Upvotes: 1
Reputation: 6668
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.
Upvotes: 1
Reputation: 44078
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.
Upvotes: 1