By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,884 Members | 949 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,884 IT Pros & Developers. It's quick & easy.

Editing HTML in a form?

P: n/a
I want to build a very basic online text editor, to allow customers to
modify their own sites' html content using a simple form with textarea
element.

I read the HTML file like so:

<?PHP

function EditText ($filepath)
{
if (!$file = file($filepath)) return false;
foreach ($file as $line) {
$value .= $line; // contains all text in file when done
}
$html = "<html><head><title>Editor</title></head>
<body>
<form method='post' action='processtext.php'>
<textarea rows='40' cols='80' name='txt' value='$value'>
<input type='submit'>
</form>
</body>
</html>";
echo $html;
return true;
}

EditText ('/sample/index.html');
?>

The problem comes when the parsed file containing html elements itself
is echoed to the browser. In itself, PHP does what it's asked, but all
browsers I tried choke on the contents of the TEXTAREA field. Best
example may be: try parsing the file containing the script itself, it
becomes a real mess.

I tried htmlspecialchars, this did not fix it. I tried addslashes to
only escape the quotes in the parsed file, also no success.

I saw one example online where 'they' preg_replaced about every possible
(x)html and php syntax element, resulting in an immensely large and slow
script. Can't imagine that's the proper way forward.

If at all possible I'd like to stay away from Javascript. Any idea if
this is a realistic approach? Are there any useable scripts available? I
searched google a lot, but I keep ending up at sites that offer html or
php editors for local use, not in a browser.

Thanks for any good tips!
Feb 15 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 15 Feb, 16:35, Schraalhans Keukenmeester <bitbuc...@invalid.spam>
wrote:
I want to build a very basic online text editor, to allow customers to
modify their own sites' html content using a simple form with textarea
element.

I read the HTML file like so:

<?PHP

function EditText ($filepath)
{
if (!$file = file($filepath)) return false;
foreach ($file as $line) {
$value .= $line; // contains all text in file when done
}
$html = "<html><head><title>Editor</title></head>
<body>
<form method='post' action='processtext.php'>
<textarea rows='40' cols='80' name='txt' value='$value'>
<input type='submit'>
</form>
</body>
</html>";
echo $html;
return true;
}

EditText ('/sample/index.html');
?>

The problem comes when the parsed file containing html elements itself
is echoed to the browser. In itself, PHP does what it's asked, but all
browsers I tried choke on the contents of the TEXTAREA field. Best
example may be: try parsing the file containing the script itself, it
becomes a real mess.

I tried htmlspecialchars, this did not fix it. I tried addslashes to
only escape the quotes in the parsed file, also no success.

I saw one example online where 'they' preg_replaced about every possible
(x)html and php syntax element, resulting in an immensely large and slow
script. Can't imagine that's the proper way forward.

If at all possible I'd like to stay away from Javascript. Any idea if
this is a realistic approach? Are there any useable scripts available? I
searched google a lot, but I keep ending up at sites that offer html or
php editors for local use, not in a browser.

Thanks for any good tips!
I haven't examined too closely how Peter does it, but FacileForms
allows one to put HTML & PHP in textareas that then get stored on the
host.

You could download that package and take a look at the various classes
to see how it's done.

Feb 15 '07 #2

P: n/a
Captain Paralytic wrote:
On 15 Feb, 16:35, Schraalhans Keukenmeester <bitbuc...@invalid.spam>
wrote:
>[snip]
Thanks for any good tips!

I haven't examined too closely how Peter does it, but FacileForms
allows one to put HTML & PHP in textareas that then get stored on the
host.

You could download that package and take a look at the various classes
to see how it's done.
Hadn't seen Facile forms yet. Looks like a rather big package, but
perhaps I can find the details I'm after. Tried a similar approach with
my provider's cms package built-in text editor, but got lost completely
in its messy hardly documented code.

I'll let you know if/when I find something useful there!
Thanks for your input Captain!

Sh.
Feb 15 '07 #3

P: n/a
Schraalhans Keukenmeester wrote:
I want to build a very basic online text editor, to allow customers to
modify their own sites' html content using a simple form with textarea
element.

I read the HTML file like so:

<?PHP

function EditText ($filepath)
{
if (!$file = file($filepath)) return false;
foreach ($file as $line) {
$value .= $line; // contains all text in file when done
}
$html = "<html><head><title>Editor</title></head>
<body>
<form method='post' action='processtext.php'>
<textarea rows='40' cols='80' name='txt' value='$value'>
<input type='submit'>
</form>
</body>
</html>";
echo $html;
return true;
}

EditText ('/sample/index.html');
?>

The problem comes when the parsed file containing html elements itself
is echoed to the browser. In itself, PHP does what it's asked, but all
browsers I tried choke on the contents of the TEXTAREA field. Best
example may be: try parsing the file containing the script itself, it
becomes a real mess.

I tried htmlspecialchars, this did not fix it. I tried addslashes to
only escape the quotes in the parsed file, also no success.

I saw one example online where 'they' preg_replaced about every possible
(x)html and php syntax element, resulting in an immensely large and slow
script. Can't imagine that's the proper way forward.

If at all possible I'd like to stay away from Javascript. Any idea if
this is a realistic approach? Are there any useable scripts available? I
searched google a lot, but I keep ending up at sites that offer html or
php editors for local use, not in a browser.

Thanks for any good tips!
htmlentities() is probably what you're looking for:

<textarea name='txt'>".htmlentities($value)."</textarea>

Also note the correction of the textarea content format!

HTH,

Ian.
Feb 15 '07 #4

P: n/a
Rik
On Thu, 15 Feb 2007 17:35:21 +0100, Schraalhans Keukenmeester
<bi*******@invalid.spamwrote:
<textarea rows='40' cols='80' name='txt' value='$value'>
Unlike other HTML element, this should be:
<textarea>$value</textarea>

Also, you might want to look into stuff like TinyMCE etc.
--
Rik Wasmus
Feb 15 '07 #5

P: n/a
Ian Taylor wrote:
Schraalhans Keukenmeester wrote:
>I want to build a very basic online text editor, to allow customers to
modify their own sites' html content using a simple form with textarea
element.

I read the HTML file like so:

<?PHP

function EditText ($filepath)
{
if (!$file = file($filepath)) return false;
foreach ($file as $line) {
$value .= $line; // contains all text in file when done
}
$html = "<html><head><title>Editor</title></head>
<body>
<form method='post' action='processtext.php'>
<textarea rows='40' cols='80' name='txt' value='$value'>
<input type='submit'>
</form>
</body>
</html>";
echo $html;
return true;
}

EditText ('/sample/index.html');
?>

The problem comes when the parsed file containing html elements itself
is echoed to the browser. In itself, PHP does what it's asked, but all
browsers I tried choke on the contents of the TEXTAREA field. Best
example may be: try parsing the file containing the script itself, it
becomes a real mess.

I tried htmlspecialchars, this did not fix it. I tried addslashes to
only escape the quotes in the parsed file, also no success.

I saw one example online where 'they' preg_replaced about every possible
(x)html and php syntax element, resulting in an immensely large and slow
script. Can't imagine that's the proper way forward.

If at all possible I'd like to stay away from Javascript. Any idea if
this is a realistic approach? Are there any useable scripts available? I
searched google a lot, but I keep ending up at sites that offer html or
php editors for local use, not in a browser.

Thanks for any good tips!

htmlentities() is probably what you're looking for:

<textarea name='txt'>".htmlentities($value)."</textarea>

Also note the correction of the textarea content format!

HTH,

Ian.
Gee, how did I miss that. Thx. Must have been late when I put this
together. Thanks a bunch! Duh! Kindergarten stuff. Why didn't I learn a
skill .... ;-) Great, now I'm done. Works for me like this!

Sh.
Feb 15 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.