473,326 Members | 2,010 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,326 software developers and data experts.

parsing complex user inputs


Hi,

I have been handed the task of updating and maintaining a web
application, written in ASP and Javascript, that takes complex
user inputs in HTML form and submits them to server-side ASP
pages for processing. The problem is, the user inputs can
become very complex, and the way this application was developed,
the inputs are all concatenated into monstrously long strings
of text that are then submited as <hidden> inputs in HTML forms
and parsed by the server-side ASP. This results in hideous strings
that go on and on like
johnsmith~1232^01^Yes^no~~|43|april

etc. etc. This code is an incredible pain to maintain and update.
There has got to be a better way to do this. I am required to
use javascript and vbscript in ASP pages on the client side,
and ASP pages for processing data on the server side. I can't
switch to a different technology, or use .NET, or anything like
that. I have to use JS and VBScript to get intricate and lengthy
user inputs and submit them for processing. I would like to
store these inputs in objects somehow and then get the data
from those objects, if possible.

If anyone could suggest a better method for doing all of this
in javascript, even just to point me in the right direction, I would
greatly appreciate it.

sven

Jul 23 '05 #1
11 2059
"Sven Neuberg" <do********@nospampls.net> wrote in message
news:kH******************@twister.southeast.rr.com ...

Hi,

I have been handed the task of updating and maintaining a web
application, written in ASP and Javascript, that takes complex
user inputs in HTML form and submits them to server-side ASP
pages for processing. The problem is, the user inputs can
become very complex, and the way this application was developed,
the inputs are all concatenated into monstrously long strings
of text that are then submited as <hidden> inputs in HTML forms
and parsed by the server-side ASP. This results in hideous strings
that go on and on like
johnsmith~1232^01^Yes^no~~|43|april

etc. etc. This code is an incredible pain to maintain and update.
There has got to be a better way to do this. I am required to
use javascript and vbscript in ASP pages on the client side,
and ASP pages for processing data on the server side. I can't
switch to a different technology, or use .NET, or anything like
that. I have to use JS and VBScript to get intricate and lengthy
user inputs and submit them for processing. I would like to
store these inputs in objects somehow and then get the data
from those objects, if possible.

If anyone could suggest a better method for doing all of this
in javascript, even just to point me in the right direction, I would
greatly appreciate it.

sven


It sounds like the user fills in numerous fields and, on form submission,
the data is concatenated into a single (hidden) field for passing to the
server where it is parsed (perhaps using "Split()"), validated, and
processed.

One option is remove the concatenation+parsing and just refer to each file
via "Request.Form("fieldname") on the server.

Is any validation done on the client-side?

Is any manipulation done on the client-side?

Jul 23 '05 #2
Sven Neuberg wrote:
Hi,

I have been handed the task of updating and maintaining a web
application, written in ASP and Javascript, that takes complex
user inputs in HTML form and submits them to server-side ASP
pages for processing. The problem is, the user inputs can
become very complex, and the way this application was developed,
the inputs are all concatenated into monstrously long strings
of text that are then submited as <hidden> inputs in HTML forms
and parsed by the server-side ASP. This results in hideous strings
that go on and on like
johnsmith~1232^01^Yes^no~~|43|april

etc. etc. This code is an incredible pain to maintain and update.
There has got to be a better way to do this. I am required to
use javascript and vbscript in ASP pages on the client side,
and ASP pages for processing data on the server side. I can't
switch to a different technology, or use .NET, or anything like
that. I have to use JS and VBScript to get intricate and lengthy
user inputs and submit them for processing. I would like to
store these inputs in objects somehow and then get the data
from those objects, if possible.
Everyone would like to be able to serialize client-side JavaScript
objects and send them to the server, unfortunately HTTP doesn't work
that way. To get the data to the server, you have to make an HTTP
request (usually GET or POST). The only thing you can send to the server
with a GET or POST are HTTP headers (which client-side JavaScript has no
access to without using the XML HTTP Request object) and the URL itself.

So at some point, you need to turn your complex data structure into
delimited text, or text attached to multiple attributes, or something,
to get it to the server.

The XML HTTP Request object does not change this, except it gives you
the ability to send custom HTTP headers and POST data without a <form>.
If anyone could suggest a better method for doing all of this
in javascript, even just to point me in the right direction, I would
greatly appreciate it.


If you are trying to move complex client-side data structures to the
server, the only way to do it is to "serialize" it by doing what the
previous author of the site you must maintain has done, and then
reconstruct the data structure on the server from the "serialized" data
(delimited strings).

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #3
On Mon, 25 Oct 2004 21:15:57 GMT, in comp.lang.javascript you wrote:
Sven Neuberg wrote:

Everyone would like to be able to serialize client-side JavaScript
objects and send them to the server, unfortunately HTTP doesn't work
that way. To get the data to the server, you have to make an HTTP
request (usually GET or POST). The only thing you can send to the server
with a GET or POST are HTTP headers (which client-side JavaScript has no
access to without using the XML HTTP Request object) and the URL itself.


What about using WDDX to ease the parsing woes?

Jamie
Jul 23 '05 #4

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:4Zcfd.304707$MQ5.33947@attbi_s52...

It sounds like the user fills in numerous fields and, on form submission,
the data is concatenated into a single (hidden) field for passing to the
server where it is parsed (perhaps using "Split()"), validated, and
processed.

Yes, and not only that, there could be a dozen "sets" of this information,
all in one very long hidden field.

One option is remove the concatenation+parsing and just refer to each file
via "Request.Form("fieldname") on the server.

I'm not sure what you mean, sorry.

Is any validation done on the client-side?

Yes, quite a bit.

Is any manipulation done on the client-side?


Yes, because the user may choose to go back and edit some of the
fields, so there is quite a bit of parsing of the strings going on.

thank you,

sven
Jul 23 '05 #5

"Jamie Jackson" <mc*************************@hotmail.com> wrote in message
news:hl********************************@4ax.com...


What about using WDDX to ease the parsing woes?

Jamie

I have never heard of it, but now I am looking at www.openwddx.org to
see if it will help. Thank you for the suggestion.

sven

Jul 23 '05 #6
"Sven Neuberg" <do********@nospampls.net> skrev i meddelandet
news:kH******************@twister.southeast.rr.com ...

Hi,

I have been handed the task of updating and maintaining a web
application, written in ASP and Javascript, that takes complex
user inputs in HTML form and submits them to server-side ASP
pages for processing. The problem is, the user inputs can
become very complex, and the way this application was developed,
the inputs are all concatenated into monstrously long strings
of text that are then submited as <hidden> inputs in HTML forms
and parsed by the server-side ASP. This results in hideous strings
that go on and on like
johnsmith~1232^01^Yes^no~~|43|april


<snip>

What happens if a user inputs one of the delimiting characters ("Joh|n
Smi~th")?

That problem is solved if you write Javascript to serialize/unserialize
arrays, and the same code in your server-side language.

For instance, say you collect form values into an array like:
var theThing = new Array("johnsmith", "Yes", 1232);

You could convert this into something like:
Array{key sz:1{0} string sz:9{johnsmith} key sz:1{1} string sz:3{Yes} key
sz:1{2} int sz:4{1232}}

You post it to the server, which reconstitutes the array. This would work
regardless of the input values and it's a bit easier to maintain.

Joakim Braun
Jul 23 '05 #7
Joakim Braun wrote:
"Sven Neuberg" <do********@nospampls.net> skrev i meddelandet
news:kH******************@twister.southeast.rr.com ...

Hi,

I have been handed the task of updating and maintaining a web
application, written in ASP and Javascript, that takes complex
user inputs in HTML form and submits them to server-side ASP
pages for processing. The problem is, the user inputs can
become very complex, and the way this application was developed,
the inputs are all concatenated into monstrously long strings
of text that are then submited as <hidden> inputs in HTML forms
and parsed by the server-side ASP. This results in hideous strings
that go on and on like
johnsmith~1232^01^Yes^no~~|43|april


<snip>

What happens if a user inputs one of the delimiting characters ("Joh|n
Smi~th")?

That problem is solved if you write Javascript to serialize/unserialize
arrays, and the same code in your server-side language.

For instance, say you collect form values into an array like:
var theThing = new Array("johnsmith", "Yes", 1232);

You could convert this into something like:
Array{key sz:1{0} string sz:9{johnsmith} key sz:1{1} string sz:3{Yes} key
sz:1{2} int sz:4{1232}}

You post it to the server, which reconstitutes the array. This would work
regardless of the input values and it's a bit easier to maintain.

Joakim Braun


One last note about this, the Object#toSource() method is well-suited to the
task of serializing your object. Try the following code in any Gecko-based
browser (Firefox, Mozilla, Netscape 7+):

var o = new Object();
o.a = 1;
o.b = '2';
o.c = new Object();
o.c.d = 3;
o.c.e = '4';
alert(o.toSource());

Unfortunately, toSource() isn't supported in IE. :(

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #8

"Joakim Braun" <jo**********@jfbraun.removethis.com> wrote in message
news:zk****************@nntpserver.swip.net...


For instance, say you collect form values into an array like:
var theThing = new Array("johnsmith", "Yes", 1232);

You could convert this into something like:
Array{key sz:1{0} string sz:9{johnsmith} key sz:1{1} string sz:3{Yes} key
sz:1{2} int sz:4{1232}}

You post it to the server, which reconstitutes the array. This would work
regardless of the input values and it's a bit easier to maintain.

Thank you! I am going to look into this. It looks like it could be very
helpful.

sven

Jul 23 '05 #9

"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:41***************@agricoreunited.com...


Unfortunately, toSource() isn't supported in IE. :(


Unfortunately, IE is our target browser, and it is a decision that is
out of my control. :(

sven

Jul 23 '05 #10
"Sven Neuberg" <do********@nospampls.net> skrev i meddelandet
news:86********************@twister.southeast.rr.c om...

"Joakim Braun" <jo**********@jfbraun.removethis.com> wrote in message
news:zk****************@nntpserver.swip.net...


For instance, say you collect form values into an array like:
var theThing = new Array("johnsmith", "Yes", 1232);

You could convert this into something like:
Array{key sz:1{0} string sz:9{johnsmith} key sz:1{1} string sz:3{Yes} key sz:1{2} int sz:4{1232}}

You post it to the server, which reconstitutes the array. This would work regardless of the input values and it's a bit easier to maintain.

Thank you! I am going to look into this. It looks like it could be very
helpful.


Below is my own code which works for my needs. It turns arrays (which may
contain other arrays as well as strings, booleans and numbers) into strings
and back. Array keys are preserved. There are probably better/more
efficient/more compact ways to do this. Note that strings are escaped,
you'll have to unescape them server-side.

Joakim Braun

***

function serializeArray(inArray){

var theResult = "";
var arrayConstructor = new Array().constructor.toString();
var thing = true;

for(var i in inArray){

var theType = typeof(inArray[i]);
var key = escape(i.toString());

theResult += "key sz:" + key.length + "{" + key + "}";

if(inArray[i] && inArray[i].constructor &&
inArray[i].constructor.toString() == arrayConstructor){

var arrData = serializeArray(inArray[i]);
theResult += "Array sz:" + arrData.length + "{" + arrData + "}";

}
else{
var str = escape(inArray[i].toString());
theResult += theType + " sz:" + str.length + "{" + str + "}";
}
}
return theResult;

}
function unserializeArray(inString){

var theResult = new Array();
var theKey = "";

// Note that arrays with zero entries will come in as "Array sz:0{}".
// The recursion will then be called with "zero string",
// which is why we check for inString.length
while(true && inString.length > 0){

var nextLeftBracketIndex = inString.indexOf("{", 0);
var theType = inString.substr(0, inString.indexOf(" ", 0));
var sizeOffset = inString.indexOf("sz:", 0) + 3;
var dataSize = parseInt(inString.substr(sizeOffset, nextLeftBracketIndex -
sizeOffset));
var theData = inString.substr(nextLeftBracketIndex + 1, dataSize);

// This will save legacy arrays
if(theKey == "")
theKey = theResult.length;

if(theType == "key"){

if(!isNaN(theData)){
theKey = parseInt(theData);
}
else if(theData.length > 0){
theKey = unescape(theData);
}
}
else if(theType == "number"){

theResult[theKey] = parseFloat(theData);
theKey = "";
}
else if(theType == "string"){

theResult[theKey] = unescape(theData);
theKey = "";
}
else if(theType == "boolean" ){

var val = new Boolean(theData);
theResult[theKey] = val == true ? true : false;
theKey = "";
}
else if(theType == "Array"){

// Recurse
theResult[theKey] = unserializeArray(theData);
theKey = "";
}
else{

prompt("Unknown object: " + theType + "\ninString: " + inString,
inString);
}

nextLeftBracketIndex = nextLeftBracketIndex + 2 + dataSize;

if(inString.length - nextLeftBracketIndex > 0){
inString = inString.substr(nextLeftBracketIndex, inString.length -
nextLeftBracketIndex);
}
else
break;
}

return theResult;

}
Jul 23 '05 #11
On Mon, 25 Oct 2004 21:42:59 GMT, "Sven Neuberg"
<do********@nospampls.net> wrote:

"Jamie Jackson" <mc*************************@hotmail.com> wrote in message
news:hl********************************@4ax.com.. .


What about using WDDX to ease the parsing woes?

Jamie

I have never heard of it, but now I am looking at www.openwddx.org to
see if it will help. Thank you for the suggestion.


When I look at that site, it's not immediately apparent what it's all
about.

Here's what I understand WDDX to be:
Each language has a couple of API functions (already) written for it:
Something like JSToWDDX and WDDXToJS for JavasScript and maybe
VBToWDDX and WDDXToVB for VB. It allows for easy serialization and
de-serialization of variables. Behind the scenes WDDX is a particular
type of XML, but you aren't exposed to those complexities, since you
use the simple API methods to create/consume the WDDX.

I'm no expert, so apologies if you find that I'm incorrect. I have,
however, used WDDX to serialize and de-serialize ColdFusion objects
within ColdFusion. I just have never taken advantage of the main
benefit -- cross-language, complex variable communication.

Thanks,
Jamie
Jul 23 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: YoBro | last post by:
Hi I have used some of this code from the PHP manual, but I am bloody hopeless with regular expressions. Was hoping somebody could offer a hand. The output of this will put the name of a form...
8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
19
by: ARK | last post by:
I am writing a search program in ASP(VBScript). The user can enter keywords and press submit. The user can separate the keywords by spaces and/or commas and key words may contain plain words,...
3
by: Pir8 | last post by:
I have a complex xml file, which contains stories within a magazine. The structure of the xml file is as follows: <?xml version="1.0" encoding="ISO-8859-1" ?> <magazine> <story>...
4
by: Earl | last post by:
I'm curious if there are others who have a better method of accepting/parsing phone numbers. I've used a couple of different techniques that are functional but I can't really say that I'm totally...
10
by: Tony | last post by:
I'm wondering if anyone has run any tests to compare the speed of parsing XML vs text in simple lists - such as: <?xml version="1.0" encoding="ISO-8859-1"?> <users> <user>User 1</user>...
5
by: gamehack | last post by:
Hi all, I was thinking about parsing equations but I can't think of any generic approach. Basically I have a struct called math_term which is something like: struct math_term { char sign; int...
3
by: davebaty | last post by:
I'm relatively new to VB programming (VB 2005), and have come across a problem parsing complex text files. Basically I have a file which has lines something like the following: max_gross_weight...
1
nine72
by: nine72 | last post by:
Ok, I am at a complete loss on this and have finally come to the XML Parsing Gods (and perhaps a PHP minor deity) for guidance… I will try my best to describe what I have going on… 1) I have 15...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.