R2i DotNetNuke® Forum

R2i wants you to have the opportunity to ask questions, post reviews, help others or just rant and rave about DotNetNuke® or any of the R2i Modules and Skins. Our team spends hour upon hour, day after day, working on custom DotNetNuke® modules and services; please feel free to ask us anything.
 
on-the-fly text import with embedded tokens
Last Post 01 Jan 1900 05:00 AM by . 1 Replies.
Printer Friendly
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Informative
mc@meirz.comUser is Offline
New Member
New Member
Posts:34

--
20 Jul 2006 08:24 AM  
In order to better manage the size and performance of some of our larger listx implementations, we've relegated some forms to DB entries outside of the listx xml setting.

These forms are of standard HTML but with inline listx tags such as Action script query references like [column,query], Session, Action and Form variable tags like [name[*ModuleID],Session], and query variable targets as well as {ACTION,value,name,Type} actions.

These can all be embedded within the form text un-escaped. The form is retrieved using a SELECT query from within the Action scripts list. You can SELECT it from within the query select list as well, although it’s too late in the process to replace query variable targets here.

That's basically it for the retrieval side. It takes a little bit of footwork however, to author these forms using listx like we are - you must handle the reserved characters [] and {}.

In three areas we encode the form text, 1. to populate the textarea, 2. to write the text to the db and 3. to post the text back through lisx. The encoded text exists only during the trip to and from its destinations - the screen and the db. Note that the encode characters are not stored in the db.

1. Presenting the text into the textarea. We SELECT the form from within the query list items. The SELECTED content requires the following SQL REPLACE logic and includes encoded text for "<" & ">" to handle the textarea HTML tags.<Pre>

Just the column (Content ntext):
Replace(Replace(Replace(Replace(Replace(Replace(CAST(Content as varchar(8000)),'[','['),']',']'),'{','{'),'}','}'),'>','>'),'<','<')

Code including the textarea:
SELECT EncapsulatedContent = '<textarea id=frmContent name=frmContent style="width:100%; height: 400px;" rows=40>' + Replace(Replace(Replace(Replace(Replace(Replace(CAST(Content as varchar(8000)),'[','['),']',']'),'{','{'),'}','}'),'>','>'),'<','<') + '</textarea>'</PRE>

2. We write the text to the db in the Actions script list and the reverse REPLACE is done but minus the encoding for the textarea tags. [myContent] is an escaped() query variable target.<PRE>

Set Content = Replace(Replace(Replace(Replace('[myContent]','[','['),']',']'),'{','{'),'}','}')

Now, for the final piece.

3. The [] & {} characters must be escaped before the form post’s, so it’s JavaScript to the rescue. I'm no expert in this area but it works. There are a couple of things to note.

<PRE>

<textarea id="EncapContent" name="EncapContent" style="Position:absolute; left:-3000; z-index:1000; visibility:hidden;" ></textarea>

<script type="text/javascript">
function EncapForm()
{
var theform;
var s;
if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) {
theform = document.Form;
}
else {
theform = document.forms["Form"];
}
s = theform.frmContent.value;
s = s.replace("\[","[");
s = s.replace(/\\[/g,"[");
s = s.replace(/\\]/g,"]");
s = s.replace(/\\{/g,"{");
theform.EncapContent.value = s.replace(/\\}/g,"}");

return true;
}
</script>
</Pre>

For some reason I could not get the regex replace to work without starting off with a dummy replace statement "s = s.replace("\[","[");". This does nothing except to allow the subsequent replace statements to work. I demonstrated the same behavior in both Fire Fox and IE. The [] & {} are reserved characters for both regex and listx, so perhaps some contention is taking place.

theform.frmContent.value holds the client text. I call an encode function that encapsulates the text string and writes it to a different and invisible textarea. If we write the encoded result back to theform.frmContent.value and submit it, you will briefly see the encoded text displayed in the textarea just prior to your post. I didn't like this behavior, therefore I write the text to be sent to another textarea and have listx process it instead. It makes for a better experience.

Notice the double backslash before the reserved characters in the regex strings. This is so listx does not process the regular expression.

If you chose to use FreeTextBox you would have to apply a similar encapsulation method.

I have not performed exhaustive testing on this method nor have I made it robust.

I hope you find it useful. Your comments and improvements are welcome.

Mike
mc@meirz.comUser is Offline
New Member
New Member
Posts:34

--
20 Jul 2006 08:32 AM  
My apologies, the HTML encode characters got interpreted and appear as '[','['),']',']'),'{','{'),'}','}'),'>','>'),'<','<') . Half of these are suppose to be encode characters.

Mike
You are not authorized to post a reply.

Active Forums 4.1
 

New York, NY • Baltimore, MD • Vienna, VA • St. Louis, MO • Seatle, WA • 410.327.0007 • info@R2Integrated.com

Bookmark & Share Bookmark and Share