Link to home
Start Free TrialLog in
Avatar of Sergy Stouk
Sergy StoukFlag for Canada

asked on

Need an Idea

I am trying to create a web page, which will allow me to edit the web template file by loading it into the plain <textarea> web form.
Some of the templates, contain <textarea> forms, which confuses the html code for the editing page.

I just need an idea of how to edit the plain text code, containing <textarea> form inside <textarea> form.

I am planning to put this code into the template and try to edit itself by loading the editing template and then loading the same template into the <textarea> of itself.

Basically a 2-level recursion.

Thanks.
Avatar of Sergy Stouk
Sergy Stouk
Flag of Canada image

ASKER

More detailed explanation:
I have a file named:
configedit.cgi which has the following:

<form method="POST" action="<ScriptWebPath>">
<textarea style="width:100%; height:400" name="data">
_hfile-data-insert_
</textarea>
<input type="submit" value=" Update! " />
<input type="hidden" name="hfile" value="_htext-form-hfile_" /></td>
<input type="hidden" name="a" value="plainconfig" /></td>
</form>

When Server gets the request, it looks up the table and sees that it has to substitute the
_hfile-data-insert_ with the value from another table, determined by parameter "name="hfile" value="_htext-form-hfile_"" from the form;
It will load the template file instead  of pattern "_hfile-data-insert_"

The file I would like to edit is "configedit.cgi" which will be inserted without any substitution AsIs instead of _hfile-data-insert_  and this file is listed above.

Surely the double <textarea> tags confuses the code and the editing page does not know how to display it properly and cuts off the plain file.

Any Ideas on how to overcome this?

You know, i think I can make a code for this:

<textarea style="width:100%; height:400" name="data">
_hfile-data-insert_
</textarea>

and simply substitute the whole textarea definition....
will try this.

But any other methods (possibly using a free JavaScript web-based text editor) is appriciated or any html tags, which I could easily remove later, which would allow me to edit the template from itself will bring you the points.



ASKER CERTIFIED SOLUTION
Avatar of Tintin
Tintin

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ChrisDrake
ChrisDrake

$template=~s/</&lt;/g; # escape the "<" html character
escaping '<' sign only is not enough, although MSIE allows some invalid unescaped characters in HTML. According to HTML standard, you should escape characters '<', '>', '"', and '&'. (And all another characters cannot be represented in current charset, like greek letters in iso-8859-1 charset, copyright sign, etc.). So, you need at least:

my %escapes = {
    '<' => '&lt;',
    '>' => '&gt;',
    '"' => '&quot;',
    '&' => '&amp;'
};

$filebody =~ s/([<>"&])/$escapes{$1}/g;

print '<TEXTAREA NAME=filebody>', $filebody, '</TEXTAREA>';
Escaping won't do.
because I need to see exactly what I am editing.
If it will be escaped, then it will not exactly look like the HTML code inside the form for the end user.
And it should look exactly, so that the person, knowing HTML would be able to visually make changes and click Submit and those changes would apply to the page he is editing inside the form and see them visually.
No escaping, because it will be confusing.
The most I though of adding and then removing from the code was the commenting Tags to show the Form that what is inserted inside the textarea is a comment, not a code, this way the text will look exactly AsIs without any confusion, you will get the points if you could give me a working example of this,
Or the Visual JavaScript Text Editor (not html WYSIWYG editors that i was able to find plenty....). Practically all of them make their own changes to tags, if inserted inside the editor and submitted. They change the Case or remove Special tags, I could not find a single JavaScript Visual TEXT editor online, which would not substitute anything upon submission and will see the difference of what is inside the editing form is Not the code, so it won't execute it (so this code can edit itself without change);
Just point me out one such JavaScript that will work this way and you will get the points.
But commenting won't do. I want the code inside the form look exactly as it is being executed.

I understand this is not an easy question and appriciate your attention.

Thanks.

Not true. Just run this:

<pre>
<textarea>&lt;textarea&gt;blah&lt;/textarea&gt;</textarea>
</pre>

through a webbrowser and you'll see that it re-renders the escaped characters for you.

(unless this thing undoes my code above, in which case it should be:

<textarea>&amp;lt;textarea&amp;gt;blah&amp;lt;/textarea&amp;gt;</textarea>
)
heh. guess it didn't unquote me :)
oh. in that case remove the pre tags.

sheesh
I will try it and let you know.
If it is that easy - this would be the best solution.
:)
I will work, because that it the method I (and thousands of others) use.

Have faith.
Thanks for an excellent and easy solution!