In many occasions it is necessary to redirect to another module. That can be to a module of PHsPeed or some external 'foreign' module. In PHsPeed you will find some useful functions that can help you with this action. There are components like the menu that can perform this task automatically, here we will show you how it's done in your code.


The standard PHP way.


The most common way is to use the header construct:



    header("Location: http://www.example.com/another-page.php");


It is also possible to add parameters like:



    header("Location: http://www.example.com/another-page.php?parm1=somevalue&parm2=somevalue");


It is allowed to use relative urls too.


In combination with PHsPeed you must be aware of the fact that you can only use this redirect in the first phase of the processing stage. PHsPeed will perform the control application initially as a 'normal' submit, followed by a number of subsequent Ajax calls. This approach will not work in ajax calls, so you cannot use this statement in render events.

Another thing to keep in mind is that you cannot redirect to PHsPeed modules this way. PHsPeed uses a system of security tokens, and expects the parameters to be sent in an AES encrypted way. That sounds complicated, but is actually easy to use as there are a few functions that perform that task.


There is also a PHsPeed variant of this function:



     function phspRedirect($url, $origin='', $parms='') 


This function is solely to be used for calling PHsPeed functions as the parameters are being encrypted into the url, including the phspeed token. Without this, the module that is called will reject the call and abort with a security error. As origin you can use the current application so that the called application 'knows' where to return to. (Postman method, the message is taken to the new module, after that, it returns to the original). 


The above methods only apply when the application is not in ajax mode. There is a way to redirect in any situation, even in Ajax calls. In the standard situation the phspRedirect is called, in ajax mode, the JavaScript will take care:



    public function Redirect($theUrl, $origin='', $parms='', $initialformmode='') 


This function is part of the spapplication object and is passed to all events in the $app parameter. 


    
   function employees_emp_no_onChange($app)  
    {
      $app->Redirect(.....);
    }
    


The initialformmode is used to set the redirected application in a certain update mode. Valid values are empty, init, add, edit, delete. This will only apply for crud modules where the form is set into the given state.