Answers.Body: <p>I can't think of a clean way to do this because of this function</p>
  
  <pre><code>public function actionVerifyEmail(): Response
  {
      // ..
      // snip 
      // ..
      if (Craft::$app-&gt;getUsers()-&gt;verifyEmailForUser($userToProcess)) {
          // ..
          // snip
          // ..
          // Redirect to the site/CP root
          $url = UrlHelper::url('');  // &lt;---- this is where we are
          return $this-&gt;redirect($url);  // ALWAYS redirect to root page
      }
  
      return $this-&gt;renderTemplate('_special/emailtaken', [
          'email' =&gt; $userToProcess-&gt;unverifiedEmail
      ]);
  }
  </code></pre>
  
  <p>A clean way to achieve this is: </p>
  
  <ol>
  <li>Handle it entirely on your own -> custom controller + custom service, send the mail manually</li>
  <li>Create a custom route to you'll only take care about activating them and overwrite the <code>actionVerifyEmail</code> - unfortunately you can't replace the controller via Dependency Injection</li>
  <li>Create a feature request and hope Pixel and Tonic will be kind enough to create a config variable / event to overwrite this value</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-07T09:08:09.823Z
Answers.Text: Thank you for these clarifications Robin. How would you handle the fact that this action would be exclusively for an update of the email and not for the first validation of the email (which works fine natively)? By checking if the user's status is STATUS_ACTIVE instead of STATUS_PENDING?
Answers.UserDisplayName: Romain P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-07T10:44:34.940Z
Answers.Text: I would not check it at all and redirect the user wherever I like / wherever my clients wants them to redirect
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-07T10:55:48.110Z
Answers.Text: To be more specific, I need to display a different alert message (by using a custom URI) on the landing page if the user has confirm his email after registration, and a different alert message (by using another custom URI) after the user has confirm his new email (after a profile update on front-end). So it matters to check the user status if it is a new user, or an already active user, to be able to adapt the confirm message of the alert. Do you think I would be able to do it by checking if STATUS_ACTIVE is true instead of STATUS_PENDING?
Answers.UserDisplayName: Romain P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-07T10:59:10.343Z
Answers.Text: Why shouldn't you? But it would be way more cleaner to display a message depending on your session Flash rather than the url since a user would be able to see the message when he/she sends a link or reloads the page
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-07T08:22:41.860Z
Answers.LastActivityDate: 2018-08-07T08:22:41.860Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I have a front-end form to update user's email address, like this example:</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8" enctype="multipart/form-data"&gt;
      {{ csrfInput() }}
      &lt;input type="hidden" name="action" value="users/save-user"&gt;
      &lt;input type="hidden" name="userId" value="{{ currentUser.id }}"&gt;
  
      &lt;label for="newEmail"&gt;New email address&lt;/label&gt;
      &lt;input type="email" name="email" value="" id="newEmail"&gt;
  
      &lt;label for="password"&gt;Password&lt;/label&gt;
      &lt;input type="password" name="password"&gt;
  
      &lt;input type="submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Once the form is submitted, Craft send a system message to the user email address, with a confirmation link. Once this link is clicked, the user is redirected to the root URL of the front-end website.</p>
  
  <p>I changed the <code>activateAccountSuccessPath</code>, but whereas it works during account activation, it doesn't works during account email update.</p>
  
  <p>Example:</p>
  
  <pre><code>'activateAccountSuccessPath' =&gt; array(
      'en' =&gt; 'my-account',
      'fr' =&gt; 'mon-compte'
  )
  </code></pre>
  
  <p>Or:</p>
  
  <pre><code>'activateAccountSuccessPath' =&gt; 'my-account'
  </code></pre>
  
  <p>I also tried to enable / disable the <code>autoLoginAfterAccountActivation</code> setting, but the redirection is still not working. Even is user is already logged in, or if he is logged out.</p>
  
  <p>I also checked the Craft logs, but I there's no error, no missing template, etc. ... nothing.</p>
  
  <p>How can I set a custom URI on this link?</p>
  
Tags: <config><emails><validation><frontend-form>
Title: How can I set a custom URI for the confirmation link of account email update from a front-end form?
ThreadText: # How can I set a custom URI for the confirmation link of account email update from a front-end form?
  
  (Asked by: username_0 on 2018-08-03)
  
  I have a front-end form to update user's email address, like this example:
  
  ```
  <form method="post" accept-charset="UTF-8" enctype="multipart/form-data">
      {{ csrfInput() }}
      <input type="hidden" name="action" value="users/save-user">
      <input type="hidden" name="userId" value="{{ currentUser.id }}">
  
      <label for="newEmail">New email address</label>
      <input type="email" name="email" value="" id="newEmail">
  
      <label for="password">Password</label>
      <input type="password" name="password">
  
      <input type="submit">
  </form>
  
  ```
  
  Once the form is submitted, Craft send a system message to the user email address, with a confirmation link. Once this link is clicked, the user is redirected to the root URL of the front-end website.
  
  I changed the `activateAccountSuccessPath`, but whereas it works during account activation, it doesn't works during account email update.
  
  Example:
  
  ```
  'activateAccountSuccessPath' => array(
      'en' => 'my-account',
      'fr' => 'mon-compte'
  )
  
  ```
  
  Or:
  
  ```
  'activateAccountSuccessPath' => 'my-account'
  
  ```
  
  I also tried to enable / disable the `autoLoginAfterAccountActivation` setting, but the redirection is still not working. Even is user is already logged in, or if he is logged out.
  
  I also checked the Craft logs, but I there's no error, no missing template, etc. ... nothing.
  
  How can I set a custom URI on this link?
  
  **Tags:** config, emails, validation, frontend-form
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-07. Score: 1 | Accepted answer
  
  I can't think of a clean way to do this because of this function
  
  ```
  public function actionVerifyEmail(): Response
  {
      // ..
      // snip 
      // ..
      if (Craft::$app->getUsers()->verifyEmailForUser($userToProcess)) {
          // ..
          // snip
          // ..
          // Redirect to the site/CP root
          $url = UrlHelper::url('');  // <---- this is where we are
          return $this->redirect($url);  // ALWAYS redirect to root page
      }
  
      return $this->renderTemplate('_special/emailtaken', [
          'email' => $userToProcess->unverifiedEmail
      ]);
  }
  
  ```
  
  A clean way to achieve this is:
  
  1. Handle it entirely on your own -> custom controller + custom service, send the mail manually
  2. Create a custom route to you'll only take care about activating them and overwrite the `actionVerifyEmail` - unfortunately you can't replace the controller via Dependency Injection
  3. Create a feature request and hope Pixel and Tonic will be kind enough to create a config variable / event to overwrite this value
  
  > **Comments:**
  > **username_0**: Thank you for these clarifications username_1. How would you handle the fact that this action would be exclusively for an update of the email and not for the first validation of the email (which works fine natively)? By checking if the user's status is STATUS_ACTIVE instead of STATUS_PENDING?  
  > **username_1**: I would not check it at all and redirect the user wherever I like / wherever my clients wants them to redirect  
  > **username_0**: To be more specific, I need to display a different alert message (by using a custom URI) on the landing page if the user has confirm his email after registration, and a different alert message (by using another custom URI) after the user has confirm his new email (after a profile update on front-end). So it matters to check the user status if it is a new user, or an already active user, to be able to adapt the confirm message of the alert. Do you think I would be able to do it by checking if STATUS_ACTIVE is true instead of STATUS_PENDING?  
  > **username_1**: Why shouldn't you? But it would be way more cleaner to display a message depending on your session Flash rather than the url since a user would be able to see the message when he/she sends a link or reloads the page  
  
  ---
  
  