From tbchambers at yahoo.com Thu Aug 2 12:04:43 2001 From: tbchambers at yahoo.com (Tim Chambers) Date: Thu Aug 5 00:18:01 2004 Subject: CGI style -- alternatives to HIDDEN parms? Message-ID: <003801c11b75$3be87c20$6f84b88d@tc5570p> Dear Perl Mongers, I am writing a Perl CGI script that updates some information in a database. The field can be hundreds of lines of text. If the field hasn't been touched, then I don't want to update it in the database. (The database logs updates, and we don't want redudant log entries.) The user will press a Submit button, at which point I need to decide which fields to update in the database. I'm assuming there isn't a simple way of detecting which fields were modified from their initial values. Am I wrong? I see my options this way: 1. Query the database and compare before deciding whether to update. The downside is that database queries are relatively expensive in time and resources. 2. Use a HIDDEN parm to forward the original field contents, then compare it with the new value to see if it's changed. But I'm concerned about sending contents (remember -- the field could be hundreds of lines of text) back and forth between client to server. Should I be? I studied http://www.w3.org/TR/html4/interact/forms.html but found nothing talking about length limits on such data. 3. Cache it on the server somehow. This would just be a cache of the database, though. I'm leaning toward #2. It seems wasteful, though. What do you all think? <>< Tim From evansj at kilnar.com Thu Aug 2 11:47:34 2001 From: evansj at kilnar.com (John Evans) Date: Thu Aug 5 00:18:01 2004 Subject: CGI style -- alternatives to HIDDEN parms? In-Reply-To: <003801c11b75$3be87c20$6f84b88d@tc5570p> Message-ID: On Thu, 2 Aug 2001, Tim Chambers wrote: > I am writing a Perl CGI script that updates some information in a > database. The field can be hundreds of lines of text. If the field > hasn't been touched, then I don't want to update it in the database. > (The database logs updates, and we don't want redudant log entries.) > The user will press a Submit button, at which point I need to decide > which fields to update in the database. I'm assuming there isn't a > simple way of detecting which fields were modified from their initial > values. Am I wrong? I see my options this way: > > 1. Query the database and compare before deciding whether to update. > The downside is that database queries are relatively expensive in time > and resources. > > 2. Use a HIDDEN parm to forward the original field contents, then > compare it with the new value to see if it's changed. But I'm > concerned about sending contents (remember -- the field could be > hundreds of lines of text) back and forth between client to server. > Should I be? I studied http://www.w3.org/TR/html4/interact/forms.html > but found nothing talking about length limits on such data. > > 3. Cache it on the server somehow. This would just be a cache of the > database, though. You could get fancy and store a checksum of the field in a hidden field. Take the checksum of the original, the checksum of the submitted field and see if they match. If they do, then the field was not changed. If they don't, you have new information to submit to the database. I'm just not sure what the chances are of two totally different sets of text generating the same checksum are. I know there are different methods, but not sure what the advantages and disadvantages are of those methods. I checked to see if there was a way to do it with Javascript, but there is no method for doing something like: if (FormName.FieldName.hasChanged()) { .... } I'm thinking that the best way would be to go with the checksum method, but since I don't know much about that, it's just a shot in the dark. -- John Evans http://evansj.kilnar.com/ -----BEGIN GEEK CODE BLOCK----- Version: 3.1 GCS d- s++:- a- C+++>++++ ULSB++++$ P+++$ L++++$ E--- W++ N+ o? K? w O- M V PS+ !PE Y+ PGP t(--) 5-- X++(+++) R+++ tv+ b+++(++++) DI+++ D++>+++ G+ e h--- r+++ y+++ ------END GEEK CODE BLOCK------ From aksuska at webflyer.com Thu Aug 2 12:30:35 2001 From: aksuska at webflyer.com (Keary Suska) Date: Thu Aug 5 00:18:01 2004 Subject: CGI style -- alternatives to HIDDEN parms? In-Reply-To: <003801c11b75$3be87c20$6f84b88d@tc5570p> Message-ID: I think your options are pretty much on the mark, but there others. If you can force your users to use JavaScript, you can have a hidden field with a name, say, "updated", and have an onChange event that sets the field. Although I don't recall exactly how a reset would effect this, so you might have to manually unset the field in that case. If JavaScript is not a reliable option, you could provide a hidden field with an MD5 hash key of the original data. Compare the MD5 of what is submitted to the hidden field to determine if it has changed. In this case a lot less data is being sent back and forth, and since the MD5 module is C code, it's pretty fast. Keary Suska Esoteritech, Inc. "Leveraging Open Source for a better Internet" > From: "Tim Chambers" > Date: Thu, 2 Aug 2001 11:04:43 -0600 > To: "Pikes Peak Perl Mongers" > Subject: CGI style -- alternatives to HIDDEN parms? > > Dear Perl Mongers, > > I am writing a Perl CGI script that updates some information in a database. > The field can be hundreds of lines of text. If the field hasn't been > touched, then I don't want to update it in the database. (The database logs > updates, and we don't want redudant log entries.) The user will press a > Submit button, at which point I need to decide which fields to update in the > database. I'm assuming there isn't a simple way of detecting which fields > were modified from their initial values. Am I wrong? I see my options this > way: > > 1. Query the database and compare before deciding whether to update. The > downside is that database queries are relatively expensive in time and > resources. > > 2. Use a HIDDEN parm to forward the original field contents, then compare it > with the new value to see if it's changed. But I'm concerned about sending > contents (remember -- the field could be hundreds of lines of text) back and > forth between client to server. Should I be? I studied > http://www.w3.org/TR/html4/interact/forms.html but found nothing talking > about length limits on such data. > > 3. Cache it on the server somehow. This would just be a cache of the > database, though. > > I'm leaning toward #2. It seems wasteful, though. > > What do you all think? > > <>< Tim > > > From aksuska at webflyer.com Thu Aug 2 13:07:27 2001 From: aksuska at webflyer.com (Keary Suska) Date: Thu Aug 5 00:18:01 2004 Subject: CGI style -- alternatives to HIDDEN parms? In-Reply-To: Message-ID: That's it--MD5 checksum. I keep forgetting the term. As I understand, MD5 is accurate to the byte. Keary Suska Esoteritech, Inc. "Leveraging Open Source for a better Internet" > From: John Evans > Date: Thu, 2 Aug 2001 12:47:34 -0400 (EDT) > To: Tim Chambers > Cc: Pikes Peak Perl Mongers > Subject: Re: CGI style -- alternatives to HIDDEN parms? > > On Thu, 2 Aug 2001, Tim Chambers wrote: > >> I am writing a Perl CGI script that updates some information in a >> database. The field can be hundreds of lines of text. If the field >> hasn't been touched, then I don't want to update it in the database. >> (The database logs updates, and we don't want redudant log entries.) >> The user will press a Submit button, at which point I need to decide >> which fields to update in the database. I'm assuming there isn't a >> simple way of detecting which fields were modified from their initial >> values. Am I wrong? I see my options this way: >> >> 1. Query the database and compare before deciding whether to update. >> The downside is that database queries are relatively expensive in time >> and resources. >> >> 2. Use a HIDDEN parm to forward the original field contents, then >> compare it with the new value to see if it's changed. But I'm >> concerned about sending contents (remember -- the field could be >> hundreds of lines of text) back and forth between client to server. >> Should I be? I studied http://www.w3.org/TR/html4/interact/forms.html >> but found nothing talking about length limits on such data. >> >> 3. Cache it on the server somehow. This would just be a cache of the >> database, though. > > You could get fancy and store a checksum of the field in a hidden field. > Take the checksum of the original, the checksum of the submitted field and > see if they match. If they do, then the field was not changed. If they > don't, you have new information to submit to the database. > > I'm just not sure what the chances are of two totally different sets of > text generating the same checksum are. I know there are different methods, > but not sure what the advantages and disadvantages are of those methods. > > I checked to see if there was a way to do it with Javascript, but there is > no method for doing something like: > if (FormName.FieldName.hasChanged()) { .... } > > I'm thinking that the best way would be to go with the checksum method, > but since I don't know much about that, it's just a shot in the dark. > > > -- > John Evans > http://evansj.kilnar.com/ > > -----BEGIN GEEK CODE BLOCK----- > Version: 3.1 > GCS d- s++:- a- C+++>++++ ULSB++++$ P+++$ L++++$ > E--- W++ N+ o? K? w O- M V PS+ !PE Y+ PGP t(--) 5-- X++(+++) > R+++ tv+ b+++(++++) DI+++ D++>+++ G+ e h--- r+++ y+++ > ------END GEEK CODE BLOCK------ > > From tbchambers at yahoo.com Thu Aug 2 16:04:01 2001 From: tbchambers at yahoo.com (Tim Chambers) Date: Thu Aug 5 00:18:01 2004 Subject: CGI style -- alternatives to HIDDEN parms? References: Message-ID: <006c01c11b96$a95d6880$6f84b88d@tc5570p> Thanks for all the suggestions. I went with the MD5 in a hidden field. Elegant. Looks like my browser client (IE5 on a PC) is sending ^M at end of lines. Once I stripped them, MD5 worked great, though. Just a few extra lines of code. <>< Tim From aksuska at webflyer.com Thu Aug 2 16:19:18 2001 From: aksuska at webflyer.com (Keary Suska) Date: Thu Aug 5 00:18:01 2004 Subject: CGI style -- alternatives to HIDDEN parms? In-Reply-To: <006c01c11b96$a95d6880$6f84b88d@tc5570p> Message-ID: FYI, according to specification, a