NetTalk Central

Author Topic: Redirecting to specific page  (Read 5283 times)

Ubaidullah

  • Full Member
  • ***
  • Posts: 125
    • View Profile
Redirecting to specific page
« on: April 08, 2011, 08:35:28 AM »
Hi All and Bruce,

How can I redirect the user to a specific page/form after validating values entered in a form? For example, when a user logs in, I want to be able to redirect them to different pages based on their level.

In php, you can do this:

header('Location: http://myurl.com/');

and it will redirect to http://myurl.com, so I could have different destinations based on different conditions.

Thanks & Regards,
Ubaidullah Nubar.

Robert Iliuta

  • Sr. Member
  • ****
  • Posts: 472
    • View Profile
    • Email
Re: Redirecting to specific page
« Reply #1 on: April 09, 2011, 11:33:45 AM »
Hallo,


I use this code if a user has IE and redirect them to another page.

<script type="text/javascript">
<!--
var browser      = navigator.appName
var ver         = navigator.appVersion
var thestart   = parseFloat(ver.indexOf("MSIE"))+1 //This finds the start of the MS version string.
var brow_ver   = parseFloat(ver.substring(thestart+4,thestart+7)) //This cuts out the bit of string we need.

if ((browser=="Microsoft Internet Explorer") && (brow_ver > 5))
   {
   window.location="IERedirect.html"; //URL to redirect to.
   }
//-->
</script>


I think you can modify for your needs and it will work.


Regards,
Robert

bshields

  • Sr. Member
  • ****
  • Posts: 392
    • View Profile
    • Inhabit
    • Email
Re: Redirecting to specific page
« Reply #2 on: April 10, 2011, 09:35:51 PM »
Hi Ubaidullah,

Because a HTML form has the destination dictated in the form itself, you cannot change the destination the form will go to once its submitted.

However, you can achieve the result in a couple of ways.

1. Javascript Hack - probably not the best way but interesting for other reasons:

<script>
window.location = 'IntroMenuLevel1?sessionid=<!-- Net:s:SessionID -->';
</script>


As soon as the javascript runs the client browser will load the page as requested.

But this really is a hack and its not playing nice with NetTalk, it useful for other reasons but not really this one.

2. Call the right NetTalk procedure once you know what you want to do. inside the form that processes the submit request. In the validate section (somewhere) once you make a decision as to what page really should be loaded then just call the page.

IF User:Level > 10
  HighLevelMenu(p_web)
  RETURN
ELSE
  LowLevelMenu(p_web)
  RETURN
.


I know thats a rough instruction and its gotta happen pretty early on you dont want your normal form sending any info to the browser before you send it to the right page.

Further: I've always had a suspission bruce has some variables that may even do this type of thing for you, but i've never chased it all the way through.

I use the method above extensively (however lots of my stuff is hand coded so i don't have worry too much about breaking normal nettalk behaviour.

Regards
Bill Shields


Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Redirecting to specific page
« Reply #3 on: April 10, 2011, 11:08:27 PM »
To follow up on what the others have said;

there are broadly speaking two ways to "redirect".

a) you pass back some code to the browser which goes something like this;
"dude, you asked for the wrong page, rather ask for xxxx"
you can do this in NetTalk by calling;

p_web.redirect('somewhere.htm')

if the redirect should be a POST rather than a GET then

p_web.redirect('somewhere.htm',,true)

(note the two commas).

This approach though is not advised for several reasons;
i) it's inefficient. The response goes all the way to the browser, and the browser has to repeat the request.
ii) It's likely to break if the request is asyncronous. (think popup-form).
iii) it must be done in the correct place, before anything else is sent to the browser.

In short - you probably don't want to do it this way.

b) Inside the code you call a procedure from inside another procedure. In essence "server side redirecting". You can do this by modifying the
p_web.self.Requestfilename
property
"by the end of the ProcessLink method".

The problem with this method is around Forms. Forms are very complex animals architecturally speaking, and require to go through a whole bunch of "stages". These stages can also vary if the form is a popup, or a page. By the time you've decided to "redirect" - if you are wanting to redirect to _another form_ then that form may miss some of the stages. This may, or may not, be an issue. If you are going to a Memory form you probably have a chance of it working though.

So If the two approaches both have flaws, then what is the solution?
The solution is to have the original procedure you are going to cope with both possible outcomes.
For example, let's say you're coding a "submit" button for an order.
The order may complete successfully, or fail. So code the "result of order" page (form) to display either the "success" result, or the "fail" result. This approach is a lot cleaner, a lot easier to maintain, and is a lot more compatible with ajax and so on.

Cheers
Bruce

Ubaidullah

  • Full Member
  • ***
  • Posts: 125
    • View Profile
Re: Redirecting to specific page
« Reply #4 on: April 14, 2011, 10:00:21 PM »
Hi Bruce,

Thanks for the reply.


b) Inside the code you call a procedure from inside another procedure. In essence "server side redirecting". You can do this by modifying the
p_web.self.Requestfilename
property
"by the end of the ProcessLink method".

If I understand correctly, this has to be done in the WebHandler proc. This breaks the logic flow as it is not obvious in the form as to what is actually happening. Also, maintenance-wise, this is an issue.

The problem with this method is around Forms. Forms are very complex animals architecturally speaking, and require to go through a whole bunch of "stages".

There is a stage where the form is submitted and nothing is generated yet. If the decision can be made at this point as to which page to display at this point, there should be no issue.

Quote
So If the two approaches both have flaws, then what is the solution?
The solution is to have the original procedure you are going to cope with both possible outcomes.
There are situations where the possible outcome is not limited to a yes/no situation. For example a purchase request system redirects to different pages depending of the type/value of item entered in the request form.

What I have done in php for example in similar situations (and is widely done in the php world) is have the form action url point to the form itself which when called on submit performs the necessary logic to determine the page to be shown. At this point, it is safe to call the php header() function because no output has been generated/sent yet.

At which stage in a NetWebForm is it safe to call another procedure (as Bill Shields suggested) ? This, I think, will achieve the desired result.

Regards,
Ubaidullah Nubar.


kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Redirecting to specific page
« Reply #5 on: April 15, 2011, 01:41:37 AM »
what I do which may or not help is:

On a memory form, make the URL on save a GSV

Add my own save button to the form

Depending what options a user chooses, I update the SSV and refresh the Save button which updates the URL on save in the browser.

HTH's

Kevin

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11244
    • View Profile
Re: Redirecting to specific page
« Reply #6 on: April 15, 2011, 03:57:16 AM »
>> If I understand correctly, this has to be done in the WebHandler proc.

no, you can set it anywhere.

>> There is a stage where the form is submitted and nothing is generated yet

PostUpdate etc routines in the Form.

Cheers
Bruce