Answers.Body: <p>I <a href="https://github.com/craftcms/docs/pull/206" rel="nofollow noreferrer">raised a PR</a> for this last week but it was closed. Apparently you're not supposed to load those templates from the front end as those variables are not auto-populated by craft. (<a href="https://github.com/craftcms/docs/pull/206/commits/8ad7fd8ea1a7b3915d77d1b2a9fe3bebadafa46c" rel="nofollow noreferrer">This code</a> fixes the problem)</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-30T15:13:53.450Z
Answers.Text: Note: use that on your own risk. I wouldn't recommend doing so
Answers.UserDisplayName: Robin Schambach
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-30T12:45:47.647Z
Answers.LastActivityDate: 2018-10-30T12:45:47.647Z
Answers.UserDisplayName: billythekid
Answers.Body: <p>The code you are currently using is for the <code>Set Password</code> form that is used when a user forgets their password and you send them a <code>Password reset email</code> as documented at <a href="https://docs.craftcms.com/v3/dev/examples/set-password-form.html" rel="nofollow noreferrer">https://docs.craftcms.com/v3/dev/examples/set-password-form.html</a>.</p>
  
  <p>Here is what I'm using to allow users to <strong>change</strong> their passwords on demand. It is based on the <code>User Profile Form</code> documented at <a href="https://docs.craftcms.com/v3/dev/examples/user-profile-form.html" rel="nofollow noreferrer">https://docs.craftcms.com/v3/dev/examples/user-profile-form.html</a></p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
      {{ csrfInput() }}
      &lt;input type="hidden" name="action" value="users/save-user"&gt;
      {# Change to suit your needs #}
      {{ redirectInput('users/'~currentUser.username) }}
      {# Get logged-in user's ID #}
      &lt;input type="hidden" name="userId" value="{{ currentUser.id }}"&gt;
  
      {% macro errorList(errors) %}
          {% if errors %}
              &lt;ul class="errors"&gt;
                  {% for error in errors %}
                      &lt;li&gt;{{ error }}&lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          {% endif %}
      {% endmacro %}
  
      {% from _self import errorList %}
  
      {# Enter current password #}
      &lt;h3&gt;&lt;label for="password"&gt;Current Password&lt;/label&gt;&lt;/h3&gt;
      &lt;input id="password" type="password" name="password"&gt;
  
      {% if account is defined %}
          {{ errorList(user.getErrors('password')) }}
      {% endif %}
  
      {# Enter new password #}
      &lt;h3&gt;&lt;label for="newPassword"&gt;New Password&lt;/label&gt;&lt;/h3&gt;
      &lt;input id="newPassword" type="password" name="newPassword"&gt;
  
      {% if account is defined %}
          {{ errorList(user.getErrors('newPassword')) }}
      {% endif %}
  
      &lt;input type="submit" value="Submit"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>UPDATE: updated form to include error handling.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-10-30T14:29:06.017Z
Answers.LastActivityDate: 2018-10-30T14:46:41.243Z
Answers.LastEditDate: 2018-10-30T14:46:41.243Z
Answers.UserDisplayName: Andrea DeMers
Body: <p>I'm trying to modify Craft 3's example '<a href="https://docs.craftcms.com/v3/dev/examples/set-password-form.html#app" rel="nofollow noreferrer">Change password</a>' form to work with a logged in Commerce 2 user, and have copied that code to <code>templates/setpassword.twig</code>.</p>
  
  <p>Two problems...</p>
  
  <p>(1) The {{ code }} and {{ id }} variables throw <em>Don't exist</em> errors.  </p>
  
  <p>(2) If I comment those variables out, I get a <em>Page not found/"Unable to resolve the request: users/setPassword"</em> error when submitting the form.</p>
  
  <p>Clearly I'm doing this totally wrong ... can anyone set me straight?</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
  {{ csrfInput() }}
  &lt;input type="hidden" name="action" value="users/set-password"&gt;
  &lt;input type="hidden" name="code" value="{{ code }}"&gt;
  &lt;input type="hidden" name="id" value="{{ id }}"&gt;
  
  &lt;h3&gt;&lt;label for="newPassword"&gt;New Password&lt;/label&gt;&lt;/h3&gt;
  &lt;input id="newPassword" type="password" name="newPassword"&gt;
  {% if errors is defined %}
      &lt;ul class="errors"&gt;
          {% for error in errors %}
              &lt;li&gt;{{ error }}&lt;/li&gt;
          {% endfor %}
      &lt;/ul&gt;
  {% endif %}
  
  &lt;input type="submit" value="Submit"&gt;
  </code></pre>
  
  <p></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-30T12:09:39.303Z
Comments.Text: Is this for when a user forgets their password, or do you want a form that allows them to change their password at their leisure?
Comments.UserDisplayName: Andrea DeMers
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-10-30T13:46:09.873Z
Comments.Text: One that lets them change it at leisure : )
Comments.UserDisplayName: James Greig
Tags: <password><frontend-form><plugin-craftcommerce2>
Title: Frontend form to change Craft Commerce user's password?
ThreadText: # Frontend form to change Craft Commerce user's password?
  
  (Asked by: username_0 on 2018-10-30)
  
  I'm trying to modify Craft 3's example '[Change password](https://docs.craftcms.com/v3/dev/examples/set-password-form.html#app)' form to work with a logged in Commerce 2 user, and have copied that code to `templates/setpassword.twig`.
  
  Two problems...
  
  (1) The {{ code }} and {{ id }} variables throw *Don't exist* errors.
  
  (2) If I comment those variables out, I get a *Page not found/"Unable to resolve the request: users/setPassword"* error when submitting the form.
  
  Clearly I'm doing this totally wrong ... can anyone set me straight?
  
  ```
  <form method="post" accept-charset="UTF-8">
  {{ csrfInput() }}
  <input type="hidden" name="action" value="users/set-password">
  <input type="hidden" name="code" value="{{ code }}">
  <input type="hidden" name="id" value="{{ id }}">
  
  <h3><label for="newPassword">New Password</label></h3>
  <input id="newPassword" type="password" name="newPassword">
  {% if errors is defined %}
      <ul class="errors">
          {% for error in errors %}
              <li>{{ error }}</li>
          {% endfor %}
      </ul>
  {% endif %}
  
  <input type="submit" value="Submit">
  
  ```
  
  **Tags:** password, frontend-form, plugin-craftcommerce2
  
  > **Comments:**
  > **username_1**: Is this for when a user forgets their password, or do you want a form that allows them to change their password at their leisure?  
  > **username_0**: One that lets them change it at leisure : )  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-10-30. Score: 4 | Accepted answer
  
  The code you are currently using is for the `Set Password` form that is used when a user forgets their password and you send them a `Password reset email` as documented at <https://docs.craftcms.com/v3/dev/examples/set-password-form.html>.
  
  Here is what I'm using to allow users to **change** their passwords on demand. It is based on the `User Profile Form` documented at <https://docs.craftcms.com/v3/dev/examples/user-profile-form.html>
  
  ```
  <form method="post" accept-charset="UTF-8">
      {{ csrfInput() }}
      <input type="hidden" name="action" value="users/save-user">
      {# Change to suit your needs #}
      {{ redirectInput('users/'~currentUser.username) }}
      {# Get logged-in user's ID #}
      <input type="hidden" name="userId" value="{{ currentUser.id }}">
  
      {% macro errorList(errors) %}
          {% if errors %}
              <ul class="errors">
                  {% for error in errors %}
                      <li>{{ error }}</li>
                  {% endfor %}
              </ul>
          {% endif %}
      {% endmacro %}
  
      {% from _self import errorList %}
  
      {# Enter current password #}
      <h3><label for="password">Current Password</label></h3>
      <input id="password" type="password" name="password">
  
      {% if account is defined %}
          {{ errorList(user.getErrors('password')) }}
      {% endif %}
  
      {# Enter new password #}
      <h3><label for="newPassword">New Password</label></h3>
      <input id="newPassword" type="password" name="newPassword">
  
      {% if account is defined %}
          {{ errorList(user.getErrors('newPassword')) }}
      {% endif %}
  
      <input type="submit" value="Submit">
  </form>
  
  ```
  
  UPDATE: updated form to include error handling.
  
  
  ---
  
  ### Answer by username_2 on 2018-10-30. Score: -1
  
  I [raised a PR](https://github.com/craftcms/docs/pull/206) for this last week but it was closed. Apparently you're not supposed to load those templates from the front end as those variables are not auto-populated by craft. ([This code](https://github.com/craftcms/docs/pull/206/commits/8ad7fd8ea1a7b3915d77d1b2a9fe3bebadafa46c) fixes the problem)
  
  > **Comments:**
  > **username_3**: Note: use that on your own risk. I wouldn't recommend doing so  
  
  ---
  
  