Answers.Body: <p>I've figured it out</p>
  
  <p>Go to GuestEntriesController.php and add this line of code on the 182nd line</p>
  
  <pre><code>$entry-&gt;id = craft()-&gt;request-&gt;getPost('entryId');
  </code></pre>
  
  <p>Then add an hidden input field with the id you wish to edit like so:</p>
  
  <pre><code>&lt;input type="hidden" name="entryId" value="{{ entry.id }}"&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-25T10:17:33.763Z
Answers.LastActivityDate: 2016-10-25T10:17:33.763Z
Answers.UserDisplayName: Branko
Answers.Body: <p>In Craft 3 / Guest Entries 2, you could pull this off without hacking Guest Entries by writing  a <a href="https://docs.craftcms.com/v3/extend/module-guide.html" rel="nofollow noreferrer">module</a> that listens to the <a href="https://github.com/craftcms/guest-entries#the-beforesaveentry-event" rel="nofollow noreferrer">beforeSaveEntry</a> event, and sets the <code>id</code> on the entry.</p>
  
  <pre class="lang-php prettyprint-override"><code>use Craft;
  use craft\elements\Entry;
  use craft\guestentries\controllers\SaveController;
  use craft\guestentries\events\SaveEvent;
  use yii\base\Event;
  use yii\web\BadRequestHttpException;
  
  // ...
  
  public function init()
  {
      // ...
  
      Event::on(SaveController::class, SaveController::EVENT_BEFORE_SAVE_ENTRY, function(SaveEvent $event) {
          $request = Craft::$app-&gt;getRequest();
  
          // Get the entry being edited
          $entryId = $request-&gt;getValidatedBodyParam('entryId');
          $currentEntry = Entry::find()-&gt;id($entryId)-&gt;anyStatus()-&gt;one();
  
          if (!$currentEntry) {
              throw new BadRequestHttpException('Invalid entry ID: ' . $entryId);
          }
  
          // Populate the guest submission with the entry ID, UID, and content ID
          $event-&gt;entry-&gt;id = $currentEntry-&gt;id;
          $event-&gt;entry-&gt;uid = $currentEntry-&gt;uid;
          $event-&gt;entry-&gt;contentId = $currentEntry-&gt;contentId;
      });
  }
  </code></pre>
  
  <p>Then in your form, add an <code>entryId</code> input set to the hashed entry ID.</p>
  
  <pre class="lang-twig prettyprint-override"><code>&lt;input type="hidden" name="entryId" value="{{ entry.id|hash }}"&gt;
  </code></pre>
  
  <p>It’s important that you hash the entry ID and use <code>getValidatedBodyParam()</code> instead of <code>getBodyParam()</code> so users can’t repurpose the form to edit <em>any</em> entry on your site.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-08T02:44:09.320Z
Answers.Text: I tried this solution but it throws an "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry" error. I thought maybe it was because Craft 3.1 moved to UID's but changing "$event->entry->id" to "$event->entry->uid" and submitting based on that doesnt seem to help. Any ideas?
Answers.UserDisplayName: Alan Miller
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2019-03-20T15:40:10.263Z
Answers.Text: Thanks to Robin for helping me fix this and updating the answer!
Answers.UserDisplayName: Alan Miller
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-05T18:44:14.203Z
Answers.Text: This was working beautifully until a Craft update and now it's freezing the site. Any idea why?
Answers.UserDisplayName: fxfuture
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-11-12T15:13:24.223Z
Answers.Text: @fxfuture Can’t think of any reason it would stop working.
Answers.UserDisplayName: Brandon Kelly
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-11-05T22:05:01.417Z
Answers.LastActivityDate: 2019-06-20T17:12:11.363Z
Answers.LastEditDate: 2019-06-20T17:12:11.363Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>I am trying to create a form that anyone can submit regardless if they are logged in or not. I found the Pixel &amp; Tonic <a href="https://github.com/pixelandtonic/GuestEntries" rel="nofollow">Guest Entries</a> plugin for this.
  Now that I've installed and configured the plugin updating entries doesn't work. Whenever I want to update an entry a new one is created instead.</p>
  
  <p>Here is the code I use:</p>
  
  <pre><code>&lt;form method="post" accept-charset="UTF-8" id="loginForm"&gt;
      {{ getCsrfInput() }}    
  
      &lt;input type="hidden" name="entryId" value="88"&gt;        
  
      &lt;input type="hidden" name="action" value="guestEntries/saveEntry"&gt;
      &lt;input type="hidden" name="redirect" value="entryform?hash={{ hash }}"&gt;
      &lt;input type="hidden" name="sectionId" value="3"&gt;
      &lt;input type="hidden" name="enabled" value="1"&gt;
  
      &lt;input type="hidden" name="title" /&gt;
  
      &lt;label for="text-naamSite"&gt;Wat is de naam van uw organisatie/onderneming?&lt;/label&gt;
      &lt;input type="text" id="text-naamSite" name="fields[naamSite]" /&gt;
  
      &lt;button type="reset" style="float:left;"&gt;Reset&lt;/button&gt;
  
      &lt;button id="send-btn" type="submit"&gt;Opslaan&lt;/button&gt;
  
      &lt;div class="clear"&gt;&lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Thanks!</p>
  
Tags: <form><saveentry><plugin-guestentries>
Title: Update form entry using the Guest Entries plugin
ThreadText: # Update form entry using the Guest Entries plugin
  
  (Asked by: username_0 on 2016-10-25)
  
  I am trying to create a form that anyone can submit regardless if they are logged in or not. I found the Pixel & Tonic [Guest Entries](https://github.com/pixelandtonic/GuestEntries) plugin for this.
  Now that I've installed and configured the plugin updating entries doesn't work. Whenever I want to update an entry a new one is created instead.
  
  Here is the code I use:
  
  ```
  <form method="post" accept-charset="UTF-8" id="loginForm">
      {{ getCsrfInput() }}    
  
      <input type="hidden" name="entryId" value="88">        
  
      <input type="hidden" name="action" value="guestEntries/saveEntry">
      <input type="hidden" name="redirect" value="entryform?hash={{ hash }}">
      <input type="hidden" name="sectionId" value="3">
      <input type="hidden" name="enabled" value="1">
  
      <input type="hidden" name="title" />
  
      <label for="text-naamSite">Wat is de naam van uw organisatie/onderneming?</label>
      <input type="text" id="text-naamSite" name="fields[naamSite]" />
  
      <button type="reset" style="float:left;">Reset</button>
  
      <button id="send-btn" type="submit">Opslaan</button>
  
      <div class="clear"></div>
  </form>
  
  ```
  
  Thanks!
  
  **Tags:** form, saveentry, plugin-guestentries
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-11-05. Score: 6 | Accepted answer
  
  In Craft 3 / Guest Entries 2, you could pull this off without hacking Guest Entries by writing a [module](https://docs.craftcms.com/v3/extend/module-guide.html) that listens to the [beforeSaveEntry](https://github.com/craftcms/guest-entries#the-beforesaveentry-event) event, and sets the `id` on the entry.
  
  ```php
  use Craft;
  use craft\elements\Entry;
  use craft\guestentries\controllers\SaveController;
  use craft\guestentries\events\SaveEvent;
  use yii\base\Event;
  use yii\web\BadRequestHttpException;
  
  // ...
  
  public function init()
  {
      // ...
  
      Event::on(SaveController::class, SaveController::EVENT_BEFORE_SAVE_ENTRY, function(SaveEvent $event) {
          $request = Craft::$app->getRequest();
  
          // Get the entry being edited
          $entryId = $request->getValidatedBodyParam('entryId');
          $currentEntry = Entry::find()->id($entryId)->anyStatus()->one();
  
          if (!$currentEntry) {
              throw new BadRequestHttpException('Invalid entry ID: ' . $entryId);
          }
  
          // Populate the guest submission with the entry ID, UID, and content ID
          $event->entry->id = $currentEntry->id;
          $event->entry->uid = $currentEntry->uid;
          $event->entry->contentId = $currentEntry->contentId;
      });
  }
  
  ```
  
  Then in your form, add an `entryId` input set to the hashed entry ID.
  
  ```twig
  <input type="hidden" name="entryId" value="{{ entry.id|hash }}">
  
  ```
  
  It’s important that you hash the entry ID and use `getValidatedBodyParam()` instead of `getBodyParam()` so users can’t repurpose the form to edit *any* entry on your site.
  
  > **Comments:**
  > **username_2**: I tried this solution but it throws an "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry" error. I thought maybe it was because Craft 3.1 moved to UID's but changing "$event->entry->id" to "$event->entry->uid" and submitting based on that doesnt seem to help. Any ideas?  
  > **username_2**: Thanks to Robin for helping me fix this and updating the answer!  
  > **username_3**: This was working beautifully until a Craft update and now it's freezing the site. Any idea why?  
  > **username_1**: @username_3 Can’t think of any reason it would stop working.  
  
  ---
  
  ### Answer by username_0 on 2016-10-25. Score: 4
  
  I've figured it out
  
  Go to GuestEntriesController.php and add this line of code on the 182nd line
  
  ```
  $entry->id = craft()->request->getPost('entryId');
  
  ```
  
  Then add an hidden input field with the id you wish to edit like so:
  
  ```
  <input type="hidden" name="entryId" value="{{ entry.id }}">
  
  ```
  
  
  ---
  
  