craftcms / guest-entries

Accept anonymous entry submissions with Craft.
MIT License
106 stars 26 forks source link

Only Titles are saved in entries, custom fields stay blank #61

Closed maxfrischknecht closed 1 year ago

maxfrischknecht commented 4 years ago

Description

Hi!

When working with the GitHub example from the plugin, it correctly populates the entry, however, it only saves the title from the form. Other custom fields (plaintext) stay empty. If the fields are required it also creates the error message "Field X cannot be blank".

The Code

{% macro errorList(errors) %}
    {% if errors %}
        <ul class="errors">
            {% for error in errors %}
                <li>{{ error }}</li>
            {% endfor %}
        </ul>
    {% endif %}
{% endmacro %}

{% from _self import errorList %}

<form method="post" action="" accept-charset="UTF-8">
    {{ csrfInput() }}
    <input type="hidden" name="action" value="guest-entries/save">
    <input type="hidden" name="sectionUid" value="1a8d051e-212e-4c81-bf83-ef28d176ac47">
    {{ redirectInput('success') }}

    <label for="title">Title</label>
    <input id="title" type="text" name="title" {% if entry is defined %} value="{{ entry.title }}" {% endif %}>

    {% if entry is defined %}
        {{ errorList(entry.getErrors('title')) }}
    {% endif %}

    <label for="firstname">firstname</label>
    <input id="firstname" type="text" name="firstname" {% if entry is defined %} value="{{ entry.firstname }}" {% endif %}>

    {% if entry is defined %}
        {{ errorList(entry.getErrors('firstname')) }}
    {% endif %}

    <label for="lastname">lastname</label>
    <input id="lastname" type="text" name="lastname" {% if entry is defined %} value="{{ entry.lastname }}" {% endif %}>

    {% if entry is defined %}
        {{ errorList(entry.getErrors('lastname')) }}
    {% endif %}

    <input type="submit" value="Publish">
</form>

Additional info

stevenjwright commented 4 years ago

The name of your fields needs to be like so: name="fields[fieldHandle]"

So, for firstname, you would have name="fields[firstname]"

Hope that helps!

AugustMiller commented 1 year ago

Plugin docs have been improved, as have the Knowledge Base and official Docs!