Only Titles are saved in entries, custom fields stay blank
maxfrischknecht opened this issue · 2 comments
maxfrischknecht commented
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
- Craft version: 3.4.28.1
- PHP version: 7.3
- Database driver & version: MariaDB 10.3
- Plugins & versions: craftcms/guest-entries: ^2.3, vlucas/phpdotenv: ^3.4.0
stevenjwright commented
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
Plugin docs have been improved, as have the Knowledge Base and official Docs!