<p>The contact form controller creates a <a href="https://github.com/craftcms/contact-form/blob/v2/src/models/Submission.php" rel="nofollow noreferrer"><code>Submission</code> model</a> with the submitted values and provides it to the template as a <code>message</code> variable. You should be able to access this variable inside your template like this:</p>
<pre class="lang-twig prettyprint-override"><code>{% set message = message ?? null %}
</code></pre>
<p>This message will contain the native properties (e.g. <code>fromName</code>, <code>fromEmail</code>):</p>
<pre class="lang-twig prettyprint-override"><code>{{ message.fromName }}
{{ message.fromEmail }}
</code></pre>
<p>If you use a single textarea field for the message body (<code>name=&quot;message&quot;</code>), the value will be available as <code>message.message</code>:</p>
<pre class="lang-twig prettyprint-override"><code>{{ message.message }}
</code></pre>
<p>If you use multiple custom fields (<code>message[body]</code>, <code>message[phoneNumber]</code>), <code>message.message</code> will be an array with those fields:</p>
<pre class="lang-twig prettyprint-override"><code>{{ message.message.body }}
{{ message.message.phoneNumber }}
</code></pre>
<p>One notable caveat is that if you're inside an included template that is included with the option <code>with_context = false</code>, the <code>message</code> variable will <em>not</em> be available. In this case, you have to go through the route manager to access it:</p>
<pre class="lang-twig prettyprint-override"><code>{% set routeParams = craft.app.getUrlManager().getRouteParams() %}
{% set message = routeParams.message ?? null %}
</code></pre>
<p>Note that this applies to contact form plugin version &lt;=3.0.0. For 3.0.0 and above, the variable has been renamed to <code>submission</code>, see the <a href="https://github.com/craftcms/contact-form/blob/main/CHANGELOG.md#300---2022-05-02" rel="nofollow noreferrer">changelog</a> for details.</p>

CC BY-SA 4.0
2022-08-03T20:04:38.093Z
Thank you very much, it works as I wanted.
Kota.M
CC BY-SA 4.0
2022-08-03T08:28:43.360Z
2022-08-03T08:28:43.360Z
MoritzLost
<p>I have been looking for how to retrieve the inserted values when the submission is failed. Other than prepared fields (Name, Email, etc.), the inserted values disappear from the fields.</p>
<p>I already found this post, but those solutions did not work for me.
<a href="https://craftcms.stackexchange.com/questions/2629/p-t-contactform-retrieving-custom-fields-value-after-submitting-form">P/T ContactForm Retrieving Custom fields Value after submitting form</a></p>
<p>My Craft is ver 3.7.50, Contact Form plugin is ver 2.5.1.</p>

<craft3><plugin-contactform>
P&T Contact Form Plugin - How to Retrieve the inserted values?
# P&T Contact Form Plugin - How to Retrieve the inserted values?

(Asked by: username_0 on 2022-08-02)

I have been looking for how to retrieve the inserted values when the submission is failed. Other than prepared fields (Name, Email, etc.), the inserted values disappear from the fields.

I already found this post, but those solutions did not work for me.
[P/T ContactForm Retrieving Custom fields Value after submitting form](https://craftcms.stackexchange.com/questions/2629/p-t-contactform-retrieving-custom-fields-value-after-submitting-form)

My Craft is ver 3.7.50, Contact Form plugin is ver 2.5.1.

**Tags:** craft3, plugin-contactform


---

## 1 answers

### Answer by username_1 on 2022-08-03. Score: 2 | Accepted answer

The contact form controller creates a Submission model with the submitted values and provides it to the template as a message variable. You should be able to access this variable inside your template like this:
{% set message = message ?? null %}

This message will contain the native properties (e.g. fromName, fromEmail):
{{ message.fromName }}
{{ message.fromEmail }}

If you use a single textarea field for the message body (name="message"), the value will be available as message.message:
{{ message.message }}

If you use multiple custom fields (message[body], message[phoneNumber]), message.message will be an array with those fields:
{{ message.message.body }}
{{ message.message.phoneNumber }}

One notable caveat is that if you're inside an included template that is included with the option with_context = false, the message variable will not be available. In this case, you have to go through the route manager to access it:
{% set routeParams = craft.app.getUrlManager().getRouteParams() %}
{% set message = routeParams.message ?? null %}

Note that this applies to contact form plugin version <=3.0.0. For 3.0.0 and above, the variable has been renamed to submission, see the changelog for details.

> **Comments:**
> **username_0**: Thank you very much, it works as I wanted.  

---

