NetTalk Central
NetTalk Web Server => Web Server - Ask For Help => Topic started by: JohanR on September 24, 2026, 02:43:47 AM
-
Hi,
What is the preferred method or embed to ensure code only runs once on form generation, popup or page loaded.
I am currently using
if (p_web.GetValue('SignInResetPassword_form:inited_') = 1)
Using code below, it runs through twice, even if checking on p_web.SetValue('SignInResetPassword_form:inited_',1)
Attached code and debuglog for initform and preupdate code/logs
thanks for any advice
Johan
InitForm Routine
DATA
LF &FILE
! Start of "Initalize the Form before anything else is done"
! [Priority 5000]
! End of "Initalize the Form before anything else is done"
CODE
! Start of "Initalize the Form before anything else is done"
! [Priority 5000]
ds_OutputDebugString('>>> InitForm <<<' & format(clock(),@t06))
if (p_web.GetValue('SignInResetPassword_form:inited_') = 1)
ds_OutputDebugString('========== 2nd time' & format(clock(),@t06))
else
ds_OutputDebugString('========== 1st time' & format(clock(),@t06))
end
! End of "Initalize the Form before anything else is done"
p_web.SetValue('SignInResetPassword_form:inited_',1)
p_web.formsettings.file = ''
p_web.formsettings.key = ''
do RestoreMem
! Start of "Initalize the Form before anything else is done"
! [Priority 5000]
-
Hi Johan,
I wanted to capture the last SAVE to File event and run code there. I put an embed there and traced the stage each time that it ran and I found that p_stage=65536 was the embed point at the very end. I put code there and it only runs ONCE. So, I would suggest you place a debug trace on the embed you want and see what stage it runs at and see if you can isolate a stage (by number) that runs only ONCE.
I am not sure that it is best practice but it works ! ( forms can get called many times as the web server services other calls and keeps coming back to the open form for that user)
Ron
-
Hi Ron
Thanks for the info, I did have the stage as part of my debug log, but somehow I posted old screenshots.
The stage stays the same.
Something is triggering the form to be requested twice.
Between the devtools log and chatgpt, it's pointing at 2 requests
GET page
↓
generate sessionStorage.id
↓
GET /NewTabID
↓
set temporary x-TabID cookie
↓
location.reload()
↓
GET page again
One of the differences
SESSIONID=MrlXGbhPPdH9e4WrF5aRVl3dZUIvvp; x-TabID=4iunbrgg
and
Cookie: SESSIONID=MrlXGbhPPdH9e4WrF5aRVl3dZUIvvp
Still trying to understand why,
but the main goal is to somewhere in the init of the form have code that should only execute once.
So looking to check what to test and how to test.
In this case, a password reset link was emailed,
if the user clicks the link, the form is loaded twice and on the second instance it blocks as the link has been used already.
I can code around this somehow, but I still would like to understand why it executes twice,
as there could be other forms or situations with the same behavior.
As with these problems I never know if I caused an issue in my code and I end up chasing all sorts of avenues. :)
thanks
Johan
GET /SignInResetPassword?coded_rdis_isn=V2AN2KI6R0VHE92QX55O3R61002Z0Z446410TQZV00I2FZDR18 HTTP/1.1 Host: localhost:442 Connection: keep-alive Cache-Control: max-age=0 sec-ch-ua: "Google Chrome";v="153", "Not_A Brand";v="8", "Chromium";v="153" sec-ch-ua-mobile: ?0 sec-ch-ua-platform: "Windows" Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 Sec-Fetch-Site: same-origin Sec-Fetch-Mode: navigate Sec-Fetch-Dest: document Referer: https://localhost:442/SignInResetPassword?coded_rdis_isn=V2AN2KI6R0VHE92QX55O3R61002Z0Z446410TQZV00I2FZDR18 Accept-Encoding: gzip, deflate, br, zstd Accept-Language: en-US,en;q=0.9 Cookie: SESSIONID=MrlXGbhPPdH9e4WrF5aRVl3dZUIvvp; x-TabID=4iunbrgg
GET /SignInResetPassword?coded_rdis_isn=V2AN2KI6R0VHE92QX55O3R61002Z0Z446410TQZV00I2FZDR18 HTTP/1.1 Host: localhost:442 Connection: keep-alive Pragma: no-cache Cache-Control: no-cache sec-ch-ua: "Google Chrome";v="153", "Not_A Brand";v="8", "Chromium";v="153" sec-ch-ua-mobile: ?0 sec-ch-ua-platform: "Windows" Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/153.0.0.0 Safari/537.36 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 Sec-Fetch-Site: same-origin Sec-Fetch-Mode: navigate Sec-Fetch-User: ?1 Sec-Fetch-Dest: document Referer: https://localhost:442/SignInResetPassword?coded_rdis_isn=V2AN2KI6R0VHE92QX55O3R61002Z0Z446410TQZV00I2FZDR18 Accept-Encoding: gzip, deflate, br, zstd Accept-Language: en-US,en;q=0.9 Cookie: SESSIONID=MrlXGbhPPdH9e4WrF5aRVl3dZUIvvp
Johan
-
Hi,
Switching on Multi TAB support creates this, have tested it with one of the examples.
Is this correct?
How to test or which embed to use on first page load to run code only once for page setup?
I don't want to go down the road of trying to check for TAB id etc...if this process is not correct and there is something I am missing.
thanks
Johan
-
HI Johan,
This does NOT sound right. Your procedure is actually getting called TWICE. I would look into that as it should be called ONCE but it will loop through and set different stages. Sounds like you have parallel procedures and they are clashing. Seems like you need to see why that is happening. I do the same type of password reset that you are talking about. It is a Memory Web Form. It has an ID that it grabs for password reset.
loc:resetGUID = p_web.GetValue('id') ! if comes in with a GUID for PW RESET
! message('Reset id: ' & loc:resetGUID)
if loc:resetGUID <> ''
p_web.SSV('loc:resetGUID', loc:resetGUID) ! keep until done.
p_web.SSV('tab',1)
end
I use another Memory Form to have them enter their E mail for password reset. I look up the e-mail and if it exists, I send them a reset link. Probably much like you did.
I would be wanting to chase down why the procedure for password reset is being called twice.
Ron
-
Hi Ron
Do you have multi TAB support set to true?
Below a snapshot of 2 different servers.
The top section is multi tab = true
The Bottom section is multi tab = false
Hoping to find a definitive way to test for form load/init and to execute code only.
Should work for both situations, multi tab or not.
thanks
Johan
-
Try checking if
p_stage=net:web:generate
net:web:generate is an equate for 0
-
Hi Jane
Thanks for reply.
That is the confusing thing , p_stage is the same in the log
Took the web1 example app and added a memory form with trace in those embeds,
If multi tab support is set to true, then those embeds execute twice and I can't see which flag/stage/event to check for 1st time
I must be missing something,
solution at the moment is to switch off multi tab support,
until I get a definitive check to use.
thanks
Johan