<p>This example code makes use of the <code>entry</code> variable set by Craft to retrieve previously posted data. The variable is set if you encounter validation errors or if you want to modify upon an already saved entry (→ include the <code>entryId</code> in a hidden input field).</p>

<p>The problem is, that you already have an <code>entry</code> variable available to your template because every entry page comes pre-populated with one (if the <a href="https://craftcms.com/docs/routing" rel="nofollow noreferrer">URI is matched</a>).</p>

<p>Easiest fix would probably be to make this single entry not match the URI set in the section's CP settings. Another idea would be to only fix that <code>title</code> problem and modify the example code:</p>

<pre><code>{% if entry is defined %} value="{{ entry.title }}"{% endif %}
</code></pre>

<p>and use this instead:</p>

<pre><code>{% if entry.errors is defined %} value="{{ entry.title }}"{% endif %}
</code></pre>

CC BY-SA 3.0
2014-08-29T20:06:17.757Z
The {%if errors %} seems to have fixed things. Thanks.
David A McInnis
CC BY-SA 3.0
2014-09-04T20:14:03.640Z
@David I corrected my answer, error messages are provided as a property of the entry variable, sorry for the confusion.
carlcs
CC BY-SA 3.0
2014-08-29T15:58:02.130Z
2017-10-26T09:27:18.950Z
2017-10-26T09:27:18.950Z
carlcs
<p>I set up a single page "Add Post" in the CP.</p>

<p>In following the example here <a href="https://craftcms.com/docs/templating/entry-form" rel="nofollow noreferrer">https://craftcms.com/docs/templating/entry-form</a> my form title input field is pre-populated with "Add Post" This is obviously not the desired result. When I include an entry id for modifying the post it grabs the title from the post as it should. </p>

<p>How do I create a new post without having a form pre-populated with "Add Post" in the title input field?</p>

<p>
    
    
    </p>

<pre><code>{% macro errorList(errors) %}
    {% if errors %}
        &lt;ul class="errors"&gt;
            {% for error in errors %}
                &lt;li&gt;{{ error }}&lt;/li&gt;
            {% endfor %}
        &lt;/ul&gt;
    {% endif %}
{% endmacro %}

{% from _self import errorList %}

&lt;label for="title"&gt;Title&lt;/label&gt;
&lt;input id="title" type="text" name="title"
    {%- if entry is defined %} value="{{ entry.title }}"{% endif -%}&gt;
</code></pre>

CC BY-SA 3.0
2014-08-29T15:57:48.500Z
How do you mean, pre-populated? Does the title field contain Add Post, or do you entries get saved with Add Post as title? Please post your form to shine some light on your problem.
Paul
<form><entry><validation>
`entry` variable pre-populated on a frontend form
# `entry` variable pre-populated on a frontend form

(Asked by: username_0 on 2014-08-29)

I set up a single page "Add Post" in the CP.
In following the example here https://craftcms.com/docs/templating/entry-form my form title input field is pre-populated with "Add Post" This is obviously not the desired result. When I include an entry id for modifying the post it grabs the title from the post as it should. 
How do I create a new post without having a form pre-populated with "Add Post" in the title input field?


{% macro errorList(errors) %}
    {% if errors %}
        
            {% for error in errors %}
                {{ error }}
            {% endfor %}
        
    {% endif %}
{% endmacro %}

{% from _self import errorList %}

Title

**Tags:** form, entry, validation
> **Comments:**
> **username_1**: How do you mean, pre-populated? Does the title field contain Add Post, or do you entries get saved with Add Post as title? Please post your form to shine some light on your problem.  

---

## 1 answers

### Answer by username_2 on 2014-08-29. Score: 1 | Accepted answer

This example code makes use of the entry variable set by Craft to retrieve previously posted data. The variable is set if you encounter validation errors or if you want to modify upon an already saved entry (→ include the entryId in a hidden input field).
The problem is, that you already have an entry variable available to your template because every entry page comes pre-populated with one (if the URI is matched).
Easiest fix would probably be to make this single entry not match the URI set in the section's CP settings. Another idea would be to only fix that title problem and modify the example code:
{% if entry is defined %} value="{{ entry.title }}"{% endif %}

and use this instead:
{% if entry.errors is defined %} value="{{ entry.title }}"{% endif %}

> **Comments:**
> **username_0**: The {%if errors %} seems to have fixed things. Thanks.  
> **username_2**: @David I corrected my answer, error messages are provided as a property of the entry variable, sorry for the confusion.  

---

