NetTalk Central

Author Topic: Direct to alternate page  (Read 3504 times)

Gordon Holfelder

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
    • Email
Direct to alternate page
« on: September 03, 2010, 12:51:50 PM »
How does one change the save URL in code based on a condition?

I would like to redirect the user to the change password form if their password has expired.

Thanks!
Gordon

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: Direct to alternate page
« Reply #1 on: September 04, 2010, 05:33:24 PM »
I just came in with exactly the same question.
Tried putting this in the GenerateForm embed
 loc:formaction = 'OtherPage'
The form now has an action of the other page, but it doesn't go there when I hit submit.

What other things have you tried?
Real programmers use copy con newapp.exe

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: Direct to alternate page
« Reply #2 on: September 04, 2010, 08:31:29 PM »
Well, the loc:formaction does put the target page into the form's action the way you'd expect, but the submit button may be doing something else...
On submit, the form reloads. I'm not sure what is telling it to do that.
In my validate, I start with -
loc:invalid=''
p_web.SetValue('retry','')
loc:alert = ''

I don't know what else is telling it there is an error and to reload rather than move on and follow the form's action. - Bruce?

Here is how I got to work very easily. I listened to my son, Dave.
He shakes his head and says,'Pop, why don't you just use a redirect?'

Oy! So there it is ...
Let the form fail and reload, except on the reload, you set up a quick redirect to where you want them to go.

In my case it is - Your account is locked! please contact your administrator!
In my validation - ValidateUpdate after the form ends, I check the users table for some stuff.
If that fails, I set a session variable -
          p_web.ssv('FailedCount',USR:failcount) !Sets a SSV to be read on the reload
           loc:alert = 'This account is locked.'
          loc:invalid = 'Failed Attempts'
          EXIT       

Then in the XHTML tab I added a routine called locked
gave it a condition if p_web.gsv('FailedCount')

and this code-
    'Please wait while we log you in...<<br/><13,10>'&|
    '<<META HTTP-EQUIV="Refresh" CONTENT="1; URL=LoginLocked"><13,10>'&|
    ''

Done! You could make the message hang for a second or two by increasing the number after Content, but sure enough it goes where you want it.





Real programmers use copy con newapp.exe

Gordon Holfelder

  • Jr. Member
  • **
  • Posts: 92
    • View Profile
    • Email
Re: Direct to alternate page
« Reply #3 on: September 07, 2010, 09:53:34 AM »
After I posted this message I dug deep and remembered a conversation with Bruce on this one. The URL associated with the "Save" button has already been determined when the page was displayed and can't really be changed. (The nature of web programming vs windows)

I like your suggestion and I will give that a try and let you know.

Thanks,
Gordon

Wolfgang Orth

  • Sr. Member
  • ****
  • Posts: 251
    • View Profile
    • oData Wolfgang Orth
Re: Direct to alternate page
« Reply #4 on: September 12, 2010, 07:25:21 AM »
Chris, Gordon,

how about redirecting the user, based on that certain condition?

In WebHandler there is this _SendFile() method:

p_web._SendFile PROCEDURE(string p_FileName,Long p_header=NET:SendHeader)

! Start of "NetTalk Method Data Section"
! [Priority 1500]

loc:parent  string(250)
loc:done        Long
loc:filename    string(255)
! [Priority 6500]

! End of "NetTalk Method Data Section"

  CODE
  ! Start of "NetTalk Method Executable Code Section"
  ! [Priority 1500]
 
 
    loc:parent = Lower(self.GetValue('_ParentProc'))
    loc:filename = SELF.GetPageName(Lower(p_FileName)) ! generated

  IF PasswordExpired = TRUE
     loc:filename = 'register.html'
  ELSE
    ! loc:filename = SELF.GetPageName(Lower(p_FileName)) ! not actualy needed, because its already generated before
  END
 
Just as a wild guess...
Wolfgang

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: Direct to alternate page
« Reply #5 on: September 12, 2010, 07:52:04 AM »
I looked at sendfile, but thought that it might break the way the server handles the current state of pages. I also didn't know where to interrupt the page generation/presentation process.

It is interesting though, to redirect inside the sendfile method by just changing the page on some condition.

I wonder if anyone has done this before?

thanks
chris
Real programmers use copy con newapp.exe

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: Direct to alternate page
« Reply #6 on: September 14, 2010, 12:18:37 AM »
Hi Chris,

Wolfgang is being modest when he says it's a guess. This was one of the things covered at the webshop.

So yes, overriding the URL at the top of _sendfile is allowed.

Cheers
Bruce

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: Direct to alternate page
« Reply #7 on: September 14, 2010, 06:03:40 PM »
Can I just p_web.Sendfile('MyOtherWebProcedure') then?

chris
Real programmers use copy con newapp.exe

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11191
    • View Profile
Re: Direct to alternate page
« Reply #8 on: September 15, 2010, 11:02:11 AM »
depends a bit where you're calling it from.
but in some cases, yes.

cheers
Bruce

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: Direct to alternate page
« Reply #9 on: September 15, 2010, 12:12:47 PM »
... or better to do a p_web.callform('MYErrorForm',0) ?
Not sure what all the stages are

chris
Real programmers use copy con newapp.exe