<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>

CC BY-SA 3.0
2016-10-25T10:17:33.763Z
2016-10-25T10:17:33.763Z
Branko
<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>

CC BY-SA 4.0
2019-03-08T02:44:09.320Z
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?
Alan Miller
CC BY-SA 4.0
2019-03-20T15:40:10.263Z
Thanks to Robin for helping me fix this and updating the answer!
Alan Miller
CC BY-SA 4.0
2021-11-05T18:44:14.203Z
This was working beautifully until a Craft update and now it's freezing the site. Any idea why?
fxfuture
CC BY-SA 4.0
2021-11-12T15:13:24.223Z
@fxfuture Can’t think of any reason it would stop working.
Brandon Kelly
CC BY-SA 4.0
2018-11-05T22:05:01.417Z
2019-06-20T17:12:11.363Z
2019-06-20T17:12:11.363Z
Brandon Kelly
<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>

<form><saveentry><plugin-guestentries>
Update form entry using the Guest Entries plugin
# 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 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:

    {{ getCsrfInput() }}    

            

    
    
    
    

    

    Wat is de naam van uw organisatie/onderneming?
    

    Reset

    Opslaan

    


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 that listens to the beforeSaveEntry event, and sets the id on the entry.
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.


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**: @fxfuture 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:


---

