NetTalk Central

Author Topic: BAD change in 8.26: SaveFile routine called on form POST ...  (Read 2864 times)

peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
BAD change in 8.26: SaveFile routine called on form POST ...
« on: September 12, 2014, 02:12:34 AM »
Hi Bruce,

I'm now facing the same problem that Brian was talking about in yesterdays NTUG: duplicate records when uploading files.
The change you've made is not a good solution as you're breaking everybodys code!

Could you please reconsider?

Peter

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: BAD change in 8.26: SaveFile routine called on form POST ...
« Reply #1 on: September 12, 2014, 07:29:32 AM »
Hi Peter,

>> The change you've made is not a good solution as you're breaking everybodies code!

Unfortunately the change is necessary because otherwise the web app does not behave properly when the async javascript send is not used. The webinar is posted though, and the explanation of what you need to do to prevent code duplication is there.

Ultimately the root problem is that the embed code being added is assuming things which are untrue. Even though it previously worked, the code itself is still incorrect. Ultimately these sorts of changes do have a positive effect on your code, because it becomes "more correct" and hence more tolerant for the future.

I understand that it's not much fun fixing code that used to work - but in this case the change is necessary.

cheers
Bruce
« Last Edit: September 30, 2014, 09:24:53 PM by Bruce »

peterH

  • Sr. Member
  • ****
  • Posts: 413
    • View Profile
Re: BAD change in 8.26: SaveFile routine called on form POST ...
« Reply #2 on: September 16, 2014, 07:08:42 AM »
Hi Bruce,

It seems like we're not yet done with this as I've come across a 'special case'  ;)

In one of my web apps I've got two different places (procedures) where the user may upload a file (and they go in different tables). Therefore I'm handling the saving-to-database in the webhandler procedure and not in the netwebform(s). I tried your proposed p_web.SetValue('nosave',1) but that value doesn't live till the webhandler kicks in - and I've also got no code in the netwebform to wrap a test around.

So I've come up with an alternative way: in the netwebform I set a sessionvalue first thing after the code statement: p_web.ssv('OkToSaveFile',1). Then, in the webhandler procedure, I test for this sessionvalue and if set to 1 I save the file AND set the sessionvalue to 0. That should ensure that the file only gets saved once.

My tests so far shows that it works as expected. I just wonder if there are any pitfalls in doing it this way?

Thanks
Peter

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: BAD change in 8.26: SaveFile routine called on form POST ...
« Reply #3 on: September 16, 2014, 10:20:32 PM »
>>  Therefore I'm handling the saving-to-database in the webhandler procedure and not in the netwebform(s).

This sounds like the root problem to me. Instead of adding code into WebHandler I would have recommended putting the code into a normal source procedure, and then calling it from multiple savefile:: routines as desired.

I'm sure putting it in WebHandler actually works, but as you see having it "outside" the form makes it harder to deal with.

Mind you, this has nothing to do with the change I made - because that was just a call in the form - specifically an extra call to savefile:: - so any code you are adding in webhandler would be called multiple times regardless of my changes.

>> in the netwebform I set a sessionvalue first thing after the code statement: p_web.ssv('OkToSaveFile',1).

that's almost certianly the wrong embed point. That code runs every time a field is changed on the form. It would be like putting it inside the TakeEvent method in a windows procedure. At a push the right place might be the top of the GenerateForm routine - but even that may not be right in some cases (page lookups being an obvious example.)

Cheers
Bruce