parsing complex user inputs

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sven Neuberg

    #1

    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



  • McKirahan

    #2
    Re: parsing complex user inputs

    "Sven Neuberg" <dontspamme@nos pampls.net> wrote in message
    news:kHafd.6882 $YL.462800@twis ter.southeast.r r.com...[color=blue]
    >
    > 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
    >[/color]

    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+p arsing 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?



    Comment

    • Grant Wagner

      #3
      Re: parsing complex user inputs

      Sven Neuberg wrote:
      [color=blue]
      > 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.[/color]

      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>.
      [color=blue]
      > 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.[/color]

      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 <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq

      Comment

      • Jamie Jackson

        #4
        Re: parsing complex user inputs

        On Mon, 25 Oct 2004 21:15:57 GMT, in comp.lang.javas cript you wrote:
        [color=blue]
        >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.[/color]

        What about using WDDX to ease the parsing woes?

        Jamie

        Comment

        • Sven Neuberg

          #5
          Re: parsing complex user inputs


          "McKirahan" <News@McKirahan .com> wrote in message
          news:4Zcfd.3047 07$MQ5.33947@at tbi_s52...[color=blue]
          >
          > 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.
          >[/color]

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

          [color=blue]
          > One option is remove the concatenation+p arsing and just refer to each file
          > via "Request.Form(" fieldname") on the server.
          >[/color]

          I'm not sure what you mean, sorry.

          [color=blue]
          > Is any validation done on the client-side?
          >[/color]

          Yes, quite a bit.

          [color=blue]
          > Is any manipulation done on the client-side?
          >[/color]

          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


          Comment

          • Sven Neuberg

            #6
            Re: parsing complex user inputs


            "Jamie Jackson" <mcsqueebagePle aseDontSpamMe@h otmail.com> wrote in message
            news:hlrqn0544c bvgortg1gsedqmi am651gbmf@4ax.c om...[color=blue]
            >
            >
            > What about using WDDX to ease the parsing woes?
            >
            > Jamie[/color]


            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



            Comment

            • Joakim Braun

              #7
              Re: parsing complex user inputs

              "Sven Neuberg" <dontspamme@nos pampls.net> skrev i meddelandet
              news:kHafd.6882 $YL.462800@twis ter.southeast.r r.com...[color=blue]
              >
              > 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[/color]

              <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("johnsmit h", "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


              Comment

              • Grant Wagner

                #8
                Re: parsing complex user inputs

                Joakim Braun wrote:
                [color=blue]
                > "Sven Neuberg" <dontspamme@nos pampls.net> skrev i meddelandet
                > news:kHafd.6882 $YL.462800@twis ter.southeast.r r.com...[color=green]
                > >
                > > 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[/color]
                >
                > <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("johnsmit h", "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[/color]

                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.toSourc e());

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

                --
                Grant Wagner <gwagner@agrico reunited.com>
                comp.lang.javas cript FAQ - http://jibbering.com/faq

                Comment

                • Sven Neuberg

                  #9
                  Re: parsing complex user inputs


                  "Joakim Braun" <joakim.braun@j fbraun.removeth is.com> wrote in message
                  news:zkpfd.9001 $1p.7613@nntpse rver.swip.net.. .[color=blue]
                  >
                  >
                  > For instance, say you collect form values into an array like:
                  > var theThing = new Array("johnsmit h", "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.
                  >[/color]


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

                  sven



                  Comment

                  • Sven Neuberg

                    #10
                    Re: parsing complex user inputs


                    "Grant Wagner" <gwagner@agrico reunited.com> wrote in message
                    news:417E6126.7 DEBDDA1@agricor eunited.com...[color=blue]
                    >
                    >
                    > Unfortunately, toSource() isn't supported in IE. :(
                    >[/color]

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

                    sven



                    Comment

                    • Joakim Braun

                      #11
                      Re: parsing complex user inputs

                      "Sven Neuberg" <dontspamme@nos pampls.net> skrev i meddelandet
                      news:86xfd.1933 9$hr3.596026@tw ister.southeast .rr.com...[color=blue]
                      >
                      > "Joakim Braun" <joakim.braun@j fbraun.removeth is.com> wrote in message
                      > news:zkpfd.9001 $1p.7613@nntpse rver.swip.net.. .[color=green]
                      > >
                      > >
                      > > For instance, say you collect form values into an array like:
                      > > var theThing = new Array("johnsmit h", "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}[/color][/color]
                      key[color=blue][color=green]
                      > > sz:1{2} int sz:4{1232}}
                      > >
                      > > You post it to the server, which reconstitutes the array. This would[/color][/color]
                      work[color=blue][color=green]
                      > > regardless of the input values and it's a bit easier to maintain.
                      > >[/color]
                      >
                      >
                      > Thank you! I am going to look into this. It looks like it could be very
                      > helpful.[/color]

                      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 arrayConstructo r = new Array().constru ctor.toString() ;
                      var thing = true;

                      for(var i in inArray){

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

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

                      if(inArray[i] && inArray[i].constructor &&
                      inArray[i].constructor.to String() == arrayConstructo r){

                      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 unserializeArra y(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 nextLeftBracket Index = inString.indexO f("{", 0);
                      var theType = inString.substr (0, inString.indexO f(" ", 0));
                      var sizeOffset = inString.indexO f("sz:", 0) + 3;
                      var dataSize = parseInt(inStri ng.substr(sizeO ffset, nextLeftBracket Index -
                      sizeOffset));
                      var theData = inString.substr (nextLeftBracke tIndex + 1, dataSize);

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

                      if(theType == "key"){

                      if(!isNaN(theDa ta)){
                      theKey = parseInt(theDat a);
                      }
                      else if(theData.leng th > 0){
                      theKey = unescape(theDat a);
                      }
                      }
                      else if(theType == "number"){

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

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

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

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

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

                      nextLeftBracket Index = nextLeftBracket Index + 2 + dataSize;

                      if(inString.len gth - nextLeftBracket Index > 0){
                      inString = inString.substr (nextLeftBracke tIndex, inString.length -
                      nextLeftBracket Index);
                      }
                      else
                      break;
                      }

                      return theResult;

                      }


                      Comment

                      • Jamie Jackson

                        #12
                        Re: parsing complex user inputs

                        On Mon, 25 Oct 2004 21:42:59 GMT, "Sven Neuberg"
                        <dontspamme@nos pampls.net> wrote:
                        [color=blue]
                        >
                        >"Jamie Jackson" <mcsqueebagePle aseDontSpamMe@h otmail.com> wrote in message
                        >news:hlrqn0544 cbvgortg1gsedqm iam651gbmf@4ax. com...[color=green]
                        >>
                        >>
                        >> What about using WDDX to ease the parsing woes?
                        >>
                        >> Jamie[/color]
                        >
                        >
                        >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.[/color]

                        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

                        Comment

                        Working...