Page 1 of 1

Posting HTML Code from script

Posted: Thu Jun 15, 2006 1:50 am
by myitanalyst
Ok, can this be done.

I need to post from a php script several text fields that have normal text, but I also need to post some HTML code which consists of a table and hyperlinks as well.

- First can HTML Code actually be posted from a normal HTML form?
- Whether or not it can be done from a HTML form can it be done from a php script? If so how do I go about doing this?

I have tried to achieve it from an HTML form, but it seems to ignore the HTML code after the post and I'm left with just the text.

Thank You.

Posted: Thu Jun 15, 2006 1:52 am
by feyd
post your code.

Posted: Thu Jun 15, 2006 3:32 am
by lettie
Your best bet is to read up on html entities at http://uk.php.net/manual/en/function.htmlentities.php

An example of how it works is as follows.

First create your form or copy paste code below:

Code: Select all

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<form name="form1" method="post" action="htments_sub.php">
  <input name="html_code" type="text" id="html_code">
  <input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
save this as whatever.htm
Next create your php script and save it as htments_sub.php

Code: Select all

<?php
	$html_code = htmlentities($HTTP_POST_VARS["html_code"], ENT_QUOTES);
	$non_html = $HTTP_POST_VARS["html_code"];
	$html_code = trim($html_code);
	echo 'HTML CODE - ';
	echo stripslashes($html_code);
	echo '<br>';
	echo 'NON HTML CODE - ';
	echo stripslashes($non_html);
?>
The result will be to convert the characters in the text to html entities.
You can convert back with html_entity_decode() but have a read of the above link to get a feel for it.

This should give you what you want.

Posted: Thu Jun 15, 2006 7:44 pm
by myitanalyst
Thanks guys... I think I might have it.

Well... I was under the impression that I could not get HTML tags and text to actually POST to another page from a form post. So I was trying to confirm this and to find out how to actually generate a post from a pure PHP coding (not an actual form).

One site documenting HTML said it couldn't be done, but apperently they were wrong... or maybe under a certain condition it was true.

I have figured out what to do now I think. It looks like I also needed the stripslashes due to magic_quotes and I found a site that showed how to generate a post from pure PHP code (not via a form).

I am going to play with it tonight and see if I get it all and I'll post what I am doing and get some feedback.

Thanks