Answers.Body: <p>My best guess, based on what you want to do, is that you don't have the correct permissions to change the entry's status. The <a href="https://docs.craftcms.com/api/v3/craft-web-controller.html#method-requirepermission" rel="nofollow noreferrer">requirePermission</a> method kicks in and will send a 403 if you don't have permission to enable an entry.</p>
  
  <p>I think the only way to change this, is to make sure that the logged in user has the correct permission(s).</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-03T19:32:18.510Z
Answers.Text: Hi Paul - that was the first thing I thought as well. I have everything checked in the CP permission wise. It's wide open. Thank you for your suggestion though! I will look further.
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-03T19:47:21.677Z
Answers.Text: What error message is returned?
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-04T02:35:53.633Z
Answers.Text: Interesting. I've updated my question to reflect new things I've tried. I am currently getting `<pre>Forbidden: Action only available from the Control Panel</pre>`
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-04T07:32:11.153Z
Answers.Text: Well, that answers your question. Try to not use this action, but post the ID and ‘enabled’ status to actions/entries/save-entry and see where that gets you.
Answers.UserDisplayName: Paul
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-04T14:55:15.697Z
Answers.Text: Posting to that url, I'm getting `"error":"Unable to verify your data submission."` I've updated my question to show what I've got. Thank you so much for your help so far!
Answers.UserDisplayName: Damon
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-03T19:14:18.763Z
Answers.LastActivityDate: 2018-12-03T19:14:18.763Z
Answers.UserDisplayName: Paul
Answers.Body: <p>Thank you for all of the time spent Paul - I very much appreciate it.
  Instead of using ajax, I went with a more "traditional" approach. This is what my template looks like now:</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8"&gt;
      {% set redirect = 'my-custom-route' %}
      {{ csrfInput() }}
      &lt;input type="hidden" name="action" value="entries/save-entry"&gt;
      {{ redirectInput(redirect) }}
      &lt;input type="hidden" name="sectionId" value="{{ entry.section.id }}"&gt;
      &lt;input type="hidden" name="entryId" value="{{ entry.id }}"&gt;
      &lt;input type="hidden" name="enabled" value="0"&gt;
      &lt;button type="button" class="btn-danger btn-sm btn-delete"&gt;
          &lt;i class="far fa-trash-alt"&gt;&lt;/i&gt;
      &lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I have some js that is listening to the <code>.btn-delete</code> event that will display a confirmation dialog:</p>
  
  <pre><code>$(document).on('click', '.btn-delete', function (event) {
      return confirm('Are you sure you want to remove this?');
  });
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-12-04T18:06:00.063Z
Answers.LastActivityDate: 2018-12-04T18:06:00.063Z
Answers.UserDisplayName: Damon
Body: <p>I am trying to set an entires status to <code>disabled</code> from a front-end form.</p>
  
  <p>Here is the click event listener I am using:</p>
  
  <pre><code>$(document).on('click', '.delete', function (event) {
      let $this = $(event.currentTarget);
      let verify = confirm("Are you sure you want to remove this?");
  
      if (verify) {
          let params = {
              'entryId': $this.data('id'),
              'sectionId': $this.data('section'),
              'enabled': 0
          };
  
          // append CSRF token.
          params[window.csrfTokenName] = window.csrfTokenValue;
  
          onSetEntryStatus(params, function (res) {
              console.log(res);
          });
      } else {
          console.log('do nothing');
      }
  
      event.preventDefault();
  });
  </code></pre>
  
  <p>Here is my ajax method:</p>
  
  <pre><code>function onSetEntryStatus(data, callback) {
      $.ajax({
          type: 'post',
          contentType: 'application/json; charset=UTF-8',
          cache: false,
          data: data,
          url: '/actions/entries/save-entry',
          processData: false,
          dataType: 'json',
          timeout: 50000
      }).done(function (response) {
          console.log('response', response);
      }).fail(function (error) {
          // Total fail.
      });
  }
  </code></pre>
  
  <p>(also tried posting to <code>actions/entries/save-entry</code>)</p>
  
  <p>Request payload is coming across as: <code>[object Object]</code> so clearly I'm having a brain-fart moment there.</p>
  
  <p>Everything I have commented out, are things that i've seen in the console when setting the status from the CP. Currently, I am getting a 403 error back. I am able to verify that I am passing in the csrf token, so I am guessing it is because of the (incorrect) way I am sending data. </p>
  
  <p>Grateful for any suggestions!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>When logging out what params I'm sending to the ajax method:</p>
  
  <pre><code>enabled: 0
  entryId: 1465
  sectionId: 5
  _token: 'really-long-string'
  </code></pre>
  
Tags: <craft3><entry><status>
Title: How can I set an entires status via ajax from a front-end form?
ThreadText: # How can I set an entires status via ajax from a front-end form?
  
  (Asked by: username_0 on 2018-12-03)
  
  I am trying to set an entires status to `disabled` from a front-end form.
  
  Here is the click event listener I am using:
  
  ```
  $(document).on('click', '.delete', function (event) {
      let $this = $(event.currentTarget);
      let verify = confirm("Are you sure you want to remove this?");
  
      if (verify) {
          let params = {
              'entryId': $this.data('id'),
              'sectionId': $this.data('section'),
              'enabled': 0
          };
  
          // append CSRF token.
          params[window.csrfTokenName] = window.csrfTokenValue;
  
          onSetEntryStatus(params, function (res) {
              console.log(res);
          });
      } else {
          console.log('do nothing');
      }
  
      event.preventDefault();
  });
  
  ```
  
  Here is my ajax method:
  
  ```
  function onSetEntryStatus(data, callback) {
      $.ajax({
          type: 'post',
          contentType: 'application/json; charset=UTF-8',
          cache: false,
          data: data,
          url: '/actions/entries/save-entry',
          processData: false,
          dataType: 'json',
          timeout: 50000
      }).done(function (response) {
          console.log('response', response);
      }).fail(function (error) {
          // Total fail.
      });
  }
  
  ```
  
  (also tried posting to `actions/entries/save-entry`)
  
  Request payload is coming across as: `[object Object]` so clearly I'm having a brain-fart moment there.
  
  Everything I have commented out, are things that i've seen in the console when setting the status from the CP. Currently, I am getting a 403 error back. I am able to verify that I am passing in the csrf token, so I am guessing it is because of the (incorrect) way I am sending data.
  
  Grateful for any suggestions!
  
  **EDIT**
  
  When logging out what params I'm sending to the ajax method:
  
  ```
  enabled: 0
  entryId: 1465
  sectionId: 5
  _token: 'really-long-string'
  
  ```
  
  **Tags:** craft3, entry, status
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-12-03. Score: 1
  
  My best guess, based on what you want to do, is that you don't have the correct permissions to change the entry's status. The [requirePermission](https://docs.craftcms.com/api/v3/craft-web-controller.html#method-requirepermission) method kicks in and will send a 403 if you don't have permission to enable an entry.
  
  I think the only way to change this, is to make sure that the logged in user has the correct permission(s).
  
  > **Comments:**
  > **username_0**: Hi username_1 - that was the first thing I thought as well. I have everything checked in the CP permission wise. It's wide open. Thank you for your suggestion though! I will look further.  
  > **username_1**: What error message is returned?  
  > **username_0**: Interesting. I've updated my question to reflect new things I've tried. I am currently getting `<pre>Forbidden: Action only available from the Control Panel</pre>`  
  > **username_1**: Well, that answers your question. Try to not use this action, but post the ID and ‘enabled’ status to actions/entries/save-entry and see where that gets you.  
  > **username_0**: Posting to that url, I'm getting `"error":"Unable to verify your data submission."` I've updated my question to show what I've got. Thank you so much for your help so far!  
  
  ---
  
  ### Answer by username_0 on 2018-12-04. Score: 1
  
  Thank you for all of the time spent username_1 - I very much appreciate it.
  Instead of using ajax, I went with a more "traditional" approach. This is what my template looks like now:
  
  ```
  <form method="post" accept-charset="UTF-8">
      {% set redirect = 'my-custom-route' %}
      {{ csrfInput() }}
      <input type="hidden" name="action" value="entries/save-entry">
      {{ redirectInput(redirect) }}
      <input type="hidden" name="sectionId" value="{{ entry.section.id }}">
      <input type="hidden" name="entryId" value="{{ entry.id }}">
      <input type="hidden" name="enabled" value="0">
      <button type="button" class="btn-danger btn-sm btn-delete">
          <i class="far fa-trash-alt"></i>
      </button>
  </form>
  
  ```
  
  I have some js that is listening to the `.btn-delete` event that will display a confirmation dialog:
  
  ```
  $(document).on('click', '.btn-delete', function (event) {
      return confirm('Are you sure you want to remove this?');
  });
  
  ```
  
  
  ---
  
  