473,396 Members | 2,037 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Editing HTML in a form?

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
5 2209
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Dan Weeb | last post by:
Hi All, I have struggled through this far with help from many of you so thanks. I am stuck again. I am really new to this so don't be harsh :-) There are a few problems. You can run the script...
0
by: Bob Kaku | last post by:
I'm trying to create a text editing and updating capability to help someone who wants to maintain content on a web page without having to know any HTML or use a web authoring tool and FTP'ng the...
1
by: nospam | last post by:
Amazon wins patent for ordering forms, Collapsing and Maximizing Form Areas.... NAME OF PATENT Method and system for displaying and editing of information # 6,615,226 ...
2
by: Krzysztof Bartosiewicz | last post by:
Hi! I have problems with editing my VBA code. It is connected with some kind of automatic-correction mechanism in Access which I cannot find. I turned off Automatic Syntax Check in Options menu...
1
by: AndrewDucker | last post by:
I've just started working with some people that have an odd setup and I'm wondering if someone can point out a better way of doing things (or what I'm doing wrong). They have a base form class,...
3
by: Erik | last post by:
I've found several posts discussing this, but I'm still stumped. Pasted below is the HTML for a simple aspx file I created in a 1.1 environment. My goal is to give my users a rich text editor,...
5
by: =?Utf-8?B?QWRhciBXZXNsZXk=?= | last post by:
Hi All, I have a GridView inside the EditItemTemplate of a FormView. Both FormView and GridView are data bound using an ObjectDataSource. When the FormView's ObjectDataSource object has a...
12
by: Trish | last post by:
I just had a bad experience using MS Word as an HTML editor. It bloated more than 200% so I could barely recognize the essential statements; and it introduced more than 14,000 errors. Also,...
8
by: ahilar12 | last post by:
Hi experts, I have a form with many textboxes,listboxes in php.I have a edit button to edit the values in the form.once i click the edit button the existing values should be displayed so that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.