Submit HTML to Textarea in PHP via form

I want to have a text box where I can directly edit the html code. After submitting the form, the contents if textarea (with html tags) should be stored in the MySQL database. I use PHP to get the date and save it in the database. My problem is that the HTML is not properly sent to PHP. I do not get HTML code, only text. How can i fix this?

my form is as follows:

<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> 

Now form.php will be able to display the contents of the text area

 echo $_POST['html_code']; 

shows: testlink

I want: <a href="link">testlink</a>

+4
source share
4 answers

Thank you all for your answers. I found a problem. It was Joomla. Joomla removed the HTML tags when I received the lines via getVar. I should have used the JREQUEST_ALLOWRAW mask parameter to solve the problem.

 JRequest::getVar('html_code', '', 'post' , 'STRING', JREQUEST_ALLOWRAW); 
+4
source

Do you echo it to an HTML page? Because the code will be parsed into the actual link.

View the source of the output page.

+1
source

You are using the wrong encoding type.

Instead of "multipart / form-data" it should be "text / plain".

You do not need to encode data, as Doug says above; but it will be encrypted for you when you submit the form, so remember to decode before use.

+1
source

Your form should be:

 <form method="post" enctype="multipart/form-data" action="form.php"> <textarea name="html_code"> &lt;a href=&quot;link&quot;&gt;testlink&lt;/a&gt; </textarea> <input type=submit value="submit"/> </form> 

(No, this is not spoiled. They are called HTML objects )

You can use htmlentities () in PHP for this.

+1
source

All Articles