Answers.Body: <p>Using the buildForm hook, you can check for the specific form/page you are looking for and then use <strong>CRM_Utils_System::redirect</strong> to redirect.</p>
  <pre><code>if ( $formName == 'CRM_Profile_Form_Edit' &amp;&amp; $form-&gt;getVar('_gid') == 15 ) {
    //Redirect profile form that has gid = 15
    CRM_Utils_System::redirect(&quot;https://google.com&quot;); // Redirect to another URL
  }
  </code></pre>
  <p>This thread shows you how to use the buildForm hook: <a href="https://civicrm.stackexchange.com/questions/42359/how-to-create-a-custom-extension-module-with-an-example">How to create a custom extension/module (with an example)?</a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-01T04:51:04.817Z
Answers.Text: I also came across this `CRM_Core_Session::singleton()->pushUserContext("https://google.com");` but I can not figure out how to use it.
Answers.UserDisplayName: jsherk
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-08-01T04:50:04.287Z
Answers.LastActivityDate: 2022-08-01T04:50:04.287Z
Answers.UserDisplayName: jsherk
Body: <p>I am using the buildForm hook, and when a specific profile page is loaded, I am checking to see if one specific user is logged in.</p>
  <p>If that user is logged in, then I want to redirect the page somewhere else.</p>
  <p>Is there a way to redirect the page from the buildForm hook (or maybe another hook)?</p>
  
Tags: <wordpress><profile><forms>
Title: Redirecting a profile page to somewhere else using hook
ThreadText: # Redirecting a profile page to somewhere else using hook
  
  (Asked by: username_0 on 2022-07-28)
  
  I am using the buildForm hook, and when a specific profile page is loaded, I am checking to see if one specific user is logged in.
  
  If that user is logged in, then I want to redirect the page somewhere else.
  
  Is there a way to redirect the page from the buildForm hook (or maybe another hook)?
  
  **Tags:** wordpress, profile, forms
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2022-08-01. Score: 0 | Accepted answer
  
  Using the buildForm hook, you can check for the specific form/page you are looking for and then use **CRM\_Utils\_System::redirect** to redirect.
  
  ```
  if ( $formName == 'CRM_Profile_Form_Edit' && $form->getVar('_gid') == 15 ) {
    //Redirect profile form that has gid = 15
    CRM_Utils_System::redirect("https://google.com"); // Redirect to another URL
  }
  
  ```
  
  This thread shows you how to use the buildForm hook: [How to create a custom extension/module (with an example)?](https://civicrm.stackexchange.com/questions/42359/how-to-create-a-custom-extension-module-with-an-example)
  
  > **Comments:**
  > **username_0**: I also came across this `CRM_Core_Session::singleton()->pushUserContext("https://google.com");` but I can not figure out how to use it.  
  
  ---
  
  