<p>It looks like <code>setFormFieldValues()</code> has an optional second parameter related to overriding values...</p>
<p><code>public function setFormFieldValues(array $values, bool $override = true)</code></p>
<p>So, changing...</p>
<p><code>$submission-&gt;setFormFieldValues(['customField' =&gt; $customFieldValue]);</code></p>
<p>... to...</p>
<p><code>$submission-&gt;setFormFieldValues(['customField' =&gt; $customFieldValue], false);</code></p>
<p>may help with the override issue.</p>

CC BY-SA 4.0
2021-03-01T08:42:48.217Z
Yes, this was the solution. I already had found this answer myself. No idea how I missed it. Thanks for your reply.
bartpulse
CC BY-SA 4.0
2021-02-26T19:55:23.780Z
2021-02-26T19:55:23.780Z
Dan Letsche
<p>I have a custom plugin where I get a freeform submission by token. I woud like to change a value in this submission and resave the submission. When I try this the old form data gets overwritten.</p>
<pre><code>$submission = Freeform::getInstance()-&gt;submissions-&gt;getSubmissionByToken($submissionToken);

$submission-&gt;setFormFieldValues(['customField' =&gt; $customFieldValue]);

// method 1, doesn't accept type submission, should be form     
Freeform::getInstance()-&gt;submissions-&gt;storeSubmission($submission);
// method 2, old data get's overwritten, current submissiontoken changes
Craft::$app-&gt;elements-&gt;saveElement($submission);
</code></pre>

<plugin-freeform><solspace>
Editing a freeform submission entry
# Editing a freeform submission entry

(Asked by: username_0 on 2021-02-18)

I have a custom plugin where I get a freeform submission by token. I woud like to change a value in this submission and resave the submission. When I try this the old form data gets overwritten.
$submission = Freeform::getInstance()->submissions->getSubmissionByToken($submissionToken);

$submission->setFormFieldValues(['customField' => $customFieldValue]);

// method 1, doesn't accept type submission, should be form     
Freeform::getInstance()->submissions->storeSubmission($submission);
// method 2, old data get's overwritten, current submissiontoken changes
Craft::$app->elements->saveElement($submission);

**Tags:** plugin-freeform, solspace

---

## 1 answers

### Answer by username_1 on 2021-02-26. Score: 2 | Accepted answer

It looks like `setFormFieldValues()` has an optional second parameter related to overriding values...

`public function setFormFieldValues(array $values, bool $override = true)`

So, changing...

`$submission->setFormFieldValues(['customField' => $customFieldValue]);`

... to...

`$submission->setFormFieldValues(['customField' => $customFieldValue], false);`

may help with the override issue.

> **Comments:**
> **username_0**: Yes, this was the solution. I already had found this answer myself. No idea how I missed it. Thanks for your reply.  

---

